'use strict';
(function (exports) {

    var $ = null;
    var tishiData = [];
    var tingData = [];
    var BatteryTextures = {
        'battery1': huzi.res.battery_1,
        'battery2': huzi.res.battery_2,
        'battery3': huzi.res.battery_3,
        'battery4': huzi.res.battery_4,
        'battery5': huzi.res.battery_5,
    };

    var EVENT_CLEAN_ROOM = 'event_clean_room';
    var EVENT_EATCARD = 'event_eat_card';
    var EVENT_EATOVER = 'event_eat_over';

    var posConf = {
        ltqpEmojiPos: {
            0: cc.p(150, -100)
            , 1: cc.p(-150, -70)
            , 2: [cc.p(20, -70), cc.p(45, 30), cc.p(45, 30)]
            , 3: [cc.p(20, -70), cc.p(45, 30), cc.p(45, 30), cc.p(45, 30)]
        }
    };
    var posIdx = {
        2: [[0, 1], [1, 0]],
        3: [[0, 1, 2], [1, 2, 0], [2, 1, 0]],
        4: [[0, 1, 2, 3], [1, 2, 3, 0], [2, 3, 0, 1], [3, 0, 1, 2]],
    };
    var CHUPAI_HEIGHT = 480;
    var MAXROW = 4;

    var roomState = null;
    //创建
    var ROOM_STATE_CREATED = 1;
    //开始游戏
    var ROOM_STATE_ONGOING = 2;
    //结束游戏
    var ROOM_STATE_ENDED = 3;

    //位置对于玩家idx
    var position2playerArrIdx = {};

    var goldTexture = cc.textureCache.addImage(res.roomjiesan_ok_png);
    var getCardImg = function (cardname) {
        if (cardname.indexOf('NaN') >= 0) return 'backbig.png';

        var src = cardname + '.png';
        //var src = "cardcommon_" + cardname + ".png";
        if (gameData.fontType == 'common') {
            src = 'cardcommon_' + cardname + '.png';
        } else if (gameData.fontType == 'ld') {
            src = cardname + '.png';
        }
        return src;
    };

    var movecard = null;
    var movecardTmp = null;
    var positionBak = null;
    var zorderBak = null;
    var movetoxy = null;
    var movetoxybak = null;
    var movexy = null;
    var cardsXYBak = [];
    //移动的牌
    var movetocardArr = [];
    var movetocardPosArr = [];

    var PhzLayer = cc.Layer.extendEX({
        isCanChuPai: true,
        isTouchedSafeBtn: false,
        _lastTingEvent: null,
        onEnter: function () {
            cc.Layer.prototype.onEnter.call(this);
        },
        onExit: function () {
            // this.removeListener();
            // EFFECT_EMOJI.destroy();
            this.unscheduleAllCallbacks();
            this.removeAllCustomListeners();
            eventManager.removeListeners(this);
            network.removeListenersForTarget(this);

            cc.Layer.prototype.onExit.call(this);
        },
        getRootNode: function () {
            return this.getChildByName('Layer');
        },
        ctor: function (reconnectData) {
            this._super();
            position2playerArrIdx = {};
            var self = this;
            self.needBaojing = false;
            this._loadPaiPlist = false;
            self._reconnectData = reconnectData;

            loadCCSTo(res.PhzRoomLayer_json, self, 'Layer');
            window.gameLayer = this;
            return true;
        },
        setBeforeOnCCSLoadFinish: function (cb) {
            this.beforeOnCCSLoadFinish = cb;
        },
        getBeforeOnCCSLoadFinish: function (cb) {
            return this.beforeOnCCSLoadFinish;
        },
        /**
         * 改变按钮资源
         * @private
         * */
        _onChanageBtnRes: function () {
            window.huzi_anniu_type = settingData.local_hu || '1';
            window.huzi_anniu_type = parseInt(window.huzi_anniu_type) || 1;

            if (!$)
                return;

            // 胡
            var btn1 = $('nAction.bt1');
            var btn1_rotation = $('btn_rotation', btn1);
            var btnHu_204 = $('btnHu', btn1);
            if (window.huzi_anniu_type === 1) {
                safeHide(btnHu_204);
                safeHide(btn1_rotation);
                safeHide($('btn_bg', btn1));
                var anniu_hu = btn1.getChildByName('anniu_hu');
                if (!cc.sys.isObjectValid(anniu_hu)) {
                    anniu_hu = playSpAnimation_hz('zi_tx', 'anniu_hu', true);
                    anniu_hu.setName('anniu_hu');
                    anniu_hu.x = btnHu_204.x;
                    anniu_hu.y = btnHu_204.y;
                    btn1.addChild(anniu_hu);
                }
            } else if (window.huzi_anniu_type === 2) {
                safeShow(btnHu_204);
                safeShow(btn1_rotation);
                safeShow($('btn_bg', btn1));
                var anniu_hu = btn1.getChildByName('anniu_hu');
                if (cc.sys.isObjectValid(anniu_hu)) {
                    anniu_hu.removeFromParent();
                }
            }

            // 吃
            var btn2 = $('nAction.bt2');
            var btn2_rotation = $('btn_rotation', btn2);
            var btnEat_205 = $('btnEat', btn2);
            if (window.huzi_anniu_type === 1) {
                safeHide(btnEat_205);
                safeHide(btn2_rotation);
                safeHide($('btn_bg', btn2));
                var anniu_chi = btn2.getChildByName('anniu_chi');
                if (!cc.sys.isObjectValid(anniu_chi)) {
                    anniu_chi = playSpAnimation_hz('zi_tx', 'anniu_chi', true);
                    anniu_chi.setName('anniu_chi');
                    anniu_chi.x = btnEat_205.x;
                    anniu_chi.y = btnEat_205.y;
                    btn2.addChild(anniu_chi);
                }
            } else if (window.huzi_anniu_type === 2) {
                safeShow(btnEat_205);
                safeShow(btn2_rotation);
                safeShow($('btn_bg', btn2));
                var anniu_chi = btn2.getChildByName('anniu_chi');
                if (cc.sys.isObjectValid(anniu_chi)) {
                    anniu_chi.removeFromParent();
                }
            }

            // 碰
            var btn3 = $('nAction.bt3');
            var btn3_rotation = $('btn_rotation', btn3);
            var btnPeng_206 = $('btnPeng', btn3);
            if (window.huzi_anniu_type === 1) {
                safeHide(btnPeng_206);
                safeHide(btn3_rotation);
                safeHide($('btn_bg', btn3));
                var anniu_peng = btn3.getChildByName('anniu_peng');
                if (!cc.sys.isObjectValid(anniu_peng)) {
                    anniu_peng = playSpAnimation_hz('zi_tx', 'anniu_peng', true);
                    anniu_peng.setName('anniu_peng');
                    anniu_peng.x = btnPeng_206.x;
                    anniu_peng.y = btnPeng_206.y;
                    btn3.addChild(anniu_peng);
                }
            } else if (window.huzi_anniu_type === 2) {
                safeShow(btnPeng_206);
                safeShow(btn3_rotation);
                safeShow($('btn_bg', btn3));
                var anniu_peng = btn3.getChildByName('anniu_peng');
                if (cc.sys.isObjectValid(anniu_peng)) {
                    anniu_peng.removeFromParent();
                }
            }

            // 过
            var btn4 = $('nAction.bt4');
            var btn4_rotation = $('btn_rotation', btn4);
            var btnCancel_207 = $('btnGuo', btn4);
            if (window.huzi_anniu_type === 1) {
                safeHide(btn4_rotation);
                safeHide($('btn_bg', btn4));
                if (cc.sys.isObjectValid(btnCancel_207)) {
                    btnCancel_207.setTexture(huzi.res.btn_new_guo);
                }
            } else if (window.huzi_anniu_type === 2) {
                safeShow(btn4_rotation);
                safeShow($('btn_bg', btn4));
                if (cc.sys.isObjectValid(btnCancel_207)) {
                    btnCancel_207.setTexture(huzi.res.btn_old_guo);
                }
            }
        },
        changeCardSize: function () {
            // this.cardstr_storage = cc.sys.localStorage.getItem('setting_pai');
            this.cardstr_storage = settingData.local_table[303];
            cc.sys.localStorage.setItem('setting_pai', this.cardstr_storage);
            var cradstr = 'card';
            if (this.cardstr_storage == 1 || !this.cardstr_storage) {
                this.cardSize = {w: 84, h: 104};
                cradstr = 'card';
                gameData.fontType = 'deafullt';

                this.cardstr_storage = 2;
            } else {
                this.cardSize = {w: 98, h: 122};
                cradstr = 'card_common';
                gameData.fontType = 'common';

                this.cardstr_storage = 1;
            }
            Card.setSize(this.cardSize);
            Card.setCardStr(cradstr);
            this.setCardFont();

        },
        onCCSLoadFinish: function () {
            var that = this;
            $ = create$(this.getRootNode());
            MicLayer.init($('btn_mic'), this, 'paohuzi');

            this._useNewProp = true;

            // 设置版本号
            $('Version').setString('Ver.' + window.curVersion);
            getVersion('huzi', $('Version'));

            this._onChanageBtnRes();

            //获取本地摆牌方式
            if (!gameData.hz_sortId) {
                gameData.hz_sortId = cc.sys.localStorage.getItem('hz_sortId') || 2;
                gameData.hz_sortId = parseInt(gameData.hz_sortId);
            }

            try {
                if (mRoom.club_id && !mRoom.isReplay && !this.isStart) {
                    // this.assistantLayer = this.getChildByName('assistantLayer');
                    // if (!this.assistantLayer) {
                    //     this.assistantLayer = new ClubAssistantLayer();
                    //     this.assistantLayer.setName('assistantLayer');
                    //     this.addChild(this.assistantLayer);
                    // }
                }
            } catch (e) {
                console.log('error in this.assistantLayer e :' + e.toString());
                network.sendPhz(5000, 'this.assistantLayer/e:' + e.toString());
            }

            // EFFECT_EMOJI.init(this, $);
            if (mRoom.wanfatype == mRoom.HENGYANG) {
                $('effectemoji1').setPosition(cc.p(1213, 102));
                $('effectemoji2').setPosition(cc.p(1207, 617));
                $('effectemoji3').setPosition(cc.p(68, 618));

                $('btn_mic').setPosition(cc.p(1235, 357));
                $('chat').setPosition(cc.p(1140, 357));

                $('lbTime').setPosition(cc.p(210, 695));
                // $('battery').setPosition(cc.p(1075, 695));
                $('battery').setVisible(true);
                $('wifi').setVisible(true);
                $('battery').setPosition(cc.p(1100, 700));
                $('wifi').setPosition(cc.p(1050, 700));
            }
            this.cardstr_storage = cc.sys.localStorage.getItem('setting_pai');
            if (this.cardstr_storage == 1 || !this.cardstr_storage) {
                this.cardSize = {w: 84, h: 104};
            } else {
                this.cardSize = {w: 98, h: 122};
            }
            cc.sys.localStorage.setItem('setting_pai', this.cardstr_storage || 1);

            // //手牌的大小
            // this.cardSize = {w: 84, h: 104};
            //this.cardSize = {w: 98, h: 122};//同城牌的size
            this.cardScale = 1;

            // this.ltqpCapInsets = {
            //     0: cc.rect(67, 24, 25, 25),
            //     1: cc.rect(22, 60, 41, 1),
            //     2: cc.rect(67, 38, 23, 21),
            //     3: cc.rect(67, 20, 26, 26)
            // };
            this.ltqpCapInsets = {
                0: cc.rect(25, 24, 22, 28),
                1: cc.rect(67, 20, 26, 26),
                2: cc.rect(65, 18, 39, 31),
                3: cc.rect(35, 11, 57, 40)
            };
            this.ltqpRect = {
                0: cc.rect(0, 0, 122, 74),
                1: cc.rect(0, 0, 134, 62),
                2: cc.rect(0, 0, 122, 73),
                3: cc.rect(0, 0, 134, 62)
            };
            this.ltqpVoicePos = {
                0: cc.p(40, 38)
                , 1: cc.p(40, 28)
                , 2: cc.p(40, 33)
                , 3: cc.p(40, 28)
            };
            this.ltqpEmojiSize = {
                0: cc.size(80, 64),
                1: cc.size(90, 52),
                2: cc.size(84, 64),
                3: cc.size(90, 52)
            };

            this.ltqpTextDelta = {
                0: cc.p(-5, 10),
                1: cc.p(-7, 5),
                2: cc.p(-1, 5),
                3: cc.p(8, 5)
            };

            this.ltqpEmojiPos = {
                0: cc.p(0, 0),
                1: cc.p(0, 0)
                , 2: [cc.p(0, 0), cc.p(0, 0), cc.p(0, 0)]
                , 3: [cc.p(0, 0), cc.p(0, 0), cc.p(0, 0), cc.p(0, 0)]
                , 4: [cc.p(0, 0), cc.p(0, 0), cc.p(0, 0), cc.p(0, 0)]
            };
            this.ltqpPos = {
                0: cc.p(-100, -10),
                1: cc.p(40, -50),
                2: cc.p(-40, -50),
                3: cc.p(0, 0)
            };
            //是否加入成功
            this.joinRoom = false;

            //三人玩  四人玩加载不同的ccs
            if (!gameData.playerNum)
                gameData.playerNum = this.playersNum = mRoom.getPlayerNum();
            else
                this.playersNum = gameData.playerNum;
            this.playersInfo = $('playersInfo');
            var playerNodes = null;
            if (this.playersNum == 4) {
                playerNodes = ccs.load(res.PhzRoomFourPlayer_json);
            } else if (this.playersNum == 3) {
                playerNodes = ccs.load(res.PhzRoomThreeplayer_json);
            } else {
                playerNodes = ccs.load(res.PhzRoomTwoplayer_json);
            }
            this.playersInfo.addChild(playerNodes.node);

            // new animation.
            this.huAni = $('huAni');
            var ccsScene = ccs.load(huzi.res.PhzHu_json, huzi.resPath);
            var huani = ccsScene.node;
            huani.setPosition(cc.p(this.huAni.getContentSize().width / 2, this.huAni.getContentSize().height / 2));
            this.huAni.addChild(huani);
            huani.runAction(ccsScene.action);
            ccsScene.action.play('action', false);
            this.huAni.setScale(1.5);
            this.huAni.setOpacity(0);

            this.roomCleanData = null;
            this.nChiList = $('nChiList');
            this.nOpenOutLayer = $('nOpenOutLayer');
            this.nOpenOutLayer.setLocalZOrder(0);
            this.playersInfo.setLocalZOrder(1);
            this.huNode = $('HuNode', this.nOpenOutLayer);
            this.nChiList.setLocalZOrder(2);
            for (var i = 0; i < this.playersNum; i++) {
                var head = $('node.info' + i + '.head' + i, this.playersInfo);
                head.setVisible(false);
                var info = $('node.info' + i, this.playersInfo);
                info.setVisible(false);

                if (mRoom.niao == true) {
                    if (i == 2 || i == 1) {
                        var avatorbg = $('node.info' + i + '.avatorbg_' + i, this.playersInfo);
                        if (avatorbg) avatorbg.setScaleX(1.5);
                    }
                } else {
                    if (mRoom.wanfatype == mRoom.YOUXIAN || mRoom.wanfatype == mRoom.HENGYANG
                        || mRoom.wanfatype == mRoom.HENGDONG || mRoom.wanfatype == mRoom.MAOHUZI) {
                        var avatorbg = $('node.info' + i + '.avatorbg_' + i, this.playersInfo);
                        if (avatorbg) avatorbg.setScaleX(1.2);
                    } else {
                        if (i == 2 || i == 1) {
                            var avatorbg = $('node.info' + i + '.avatorbg_' + i, this.playersInfo);
                            if (avatorbg) avatorbg.setScaleX(1.1);
                        }
                    }
                }

                this['nCards' + i] = $('node.nCards' + i, this.playersInfo);
                this['txtUserName' + i] = $('node.info' + i + '.txtUserName' + i, this.playersInfo);
                this['txtHX' + i] = $('node.info' + i + '.txtHX' + i, this.playersInfo);
                this['txtHX_value_' + i] = $('node.info' + i + '.txtHX_value_' + i, this.playersInfo);
                this['txtScore' + i] = $('node.info' + i + '.txtScore' + i, this.playersInfo);
                if (i != 0) {
                    this['txtUserName' + i].setVisible(false);
                    this['txtHX' + i].setVisible(false);
                    //this["txtHX_value_" + i].setVisible(false);
                }
                this['open' + i] = new OpenCards();
                var openPos = $('node.open' + i, this.playersInfo).getPosition();
                this['open' + i].setPosition(openPos);
                this.nOpenOutLayer.addChild(this['open' + i]);
                this['open' + i].setPos(i);
                this['out' + i] = new OutCards();
                var outPos = $('node.out' + i, this.playersInfo).getPosition();
                this['out' + i].setPosition(outPos);
                this.nOpenOutLayer.addChild(this['out' + i]);
                this['out' + i].setPos(i);
            }
            if (this.isErrenwanSipai()) {
                this['open2'] = $('node.open2', this.playersInfo);
                this['nCards2'] = $('node.nCards2', this.playersInfo);
                this.open2bg = new cc.Sprite(res.table_third_0_png);
                var _size = this.open2bg.getContentSize();
                this.open2bg.setPositionX(142);
                this.open2bg.setPositionY(40);
                this['open2'].addChild(this.open2bg);
                this['open2'].setVisible(false);
            }
            this.nAction = $('nAction');
            this.nAction.setLocalZOrder(1);
            this.txtCardCount = $('game_zhang.txtCardCount');
            this.txtRound = $('txtRound');
            this.txtRoomId = $('txtRoomId');
            this.txtRoom = $('txtRoom');
            this.game_title = $('game_title');
            this.game_zhang = $('game_zhang');
            this.game_ju = $('game_ju');
            this.panelResult = $('PanelResult');
            this.nLaizi = $('nLaizi');


            this.cd = $('cd');
            this.cdtext = $('cd.cdtext');
            this.cd.setVisible(false);
            //进度条指针
            var cdbar = new cc.ProgressTimer(cc.Sprite.create(huzi.resPath+'dynamicRes/' + 'greenquan.png'));
            //console.log("===============" + this.cd.getContentSize().width / 2);
            cdbar.setPosition(cc.p(this.cd.getContentSize().width / 2, this.cd.getContentSize().height / 2 + 2));
            cdbar.setType(cc.ProgressTimer.TYPE_RADIAL);
            cdbar.setMidpoint(cc.p(0.5, 0.5));
            cdbar.setReverseDirection(true);
            cdbar.runAction(
                cc.progressTo(0.1, 100)
            );
            this.cd.addChild(cdbar);
            this.cdbar = cdbar;
            var filename = 'vbg' + (settingData.local_bgMusic[gameData.mapId] || 1);
            playMusic(filename, true);

            //重置牌摆放
            this.refresh = $('refresh');
            if (this.refresh) {
                ///1  默认 不需要改
                ///2  手牌凑成门子最多， 门子: 四/三个一样 两个一样 顺子  大小字相同
                TouchUtil.setOnclickListener(this.refresh, function () {
                    gameData.hz_sortId = (gameData.hz_sortId + 1) % 3;
                    cc.sys.localStorage.setItem('hz_sortId', gameData.hz_sortId);
                    that.resetCards();
                });
                this.refresh.setVisible(false);
            }
            //聊天
            this.chat = $('chat');
            //邀请
            this.invite = $('btnlayer.invite');
            TouchUtil.setOnclickListener(this.invite, function () {
                that.inviteFunc('weixin');
            }, {});
            TouchUtil.setOnclickListener($('btnlayer.share_v4.invite'), function () {
                that.inviteFunc('weixin');
            }, {});
            //邀请
            this.invite_liaobei = $('btnlayer.invite_liaobei');
            TouchUtil.setOnclickListener(this.invite_liaobei, function () {
                that.inviteFunc('liaobei');
            }, {});
            TouchUtil.setOnclickListener($('btnlayer.share_v4.invite_liaobei'), function () {
                that.inviteFunc('liaobei');
            }, {});
            TouchUtil.setOnclickListener($('btnlayer.share_v4.invite_xl'), function () {
                that.inviteFunc('xianliao');
            }, {});
            this.copyroom = $('btnlayer.copyroom');
            //复制房间
            this.copyroom.setVisible(false);
            TouchUtil.setOnclickListener(this.copyroom, function () {
                that.copyroomFunc();
            }, {});
            //退出
            this.tuichu = $('btnlayer.tuichu');
            TouchUtil.setOnclickListener(this.tuichu, function () {
                showMessageBox('确定要退出房间吗?', function () {
                    network.sendPhz(3003, 'Quit/' + gameData.roomId);
                }, null, false, true, true, res.tip_mark_exitroom, res.tip_icon_exitroom);
            }, {});
            //解散
            this.jiesan = $('btnlayer.jiesan');
            TouchUtil.setOnclickListener(this.jiesan, function () {
                if (window.inReview)
                    network.sendPhz(3003, 'Discard/' + gameData.roomId);
                else
                    showMessageBox('解散房间不扣房卡，是否确定解散？', function () {
                        network.sendPhz(3003, 'Discard/' + gameData.roomId);
                    }, null, false, true, true, res.tip_mark_disroom, res.tip_icon_dis);
            });

            //准备
            this.zhunbei = $('btnlayer.zhunbei');
            TouchUtil.setOnclickListener(this.zhunbei, function () {
                network.sendPhz(5000, 'Ready');
                that.zhunbei.setVisible(false);
            });
            this.zhunbei.setVisible(false);

            this.jushou = $('jushou');
            this.bujushou = $('bujushou');
            this.jushou.setVisible(false);
            this.bujushou.setVisible(false);
            //举手
            TouchUtil.setOnclickListener(this.jushou, function (node) {
                that.playJSEffect('jushou', gameData.sex);
                network.sendPhz(5000, 'Jushou/1');
            }, {});
            //不举手
            TouchUtil.setOnclickListener(this.bujushou, function (node) {
                network.sendPhz(5000, 'Jushou/2');
            }, {});
            this.lbTime = $('lbTime');
            if (mRoom.isReplay == true) {
                this.invite.setVisible(false);
                this.invite_liaobei.setVisible(false);
                if ($('btnlayer.share_v4'))
                    $('btnlayer.share_v4').setVisible(false);
                this.copyroom.setVisible(false);
                this.tuichu.setVisible(false);
                this.jiesan.setVisible(false);
            }
            if (window.inReview) {
                this.invite.setVisible(false);
                this.invite_liaobei.setVisible(false);
                if ($('btnlayer.share_v4'))
                    $('btnlayer.share_v4').setVisible(false);
                this.copyroom.setVisible(false);
                this.jiesan.setPositionX(1280 / 2);
            }
            this.imgAct = $('imgAct');
            this.aniAct = $('aniAct');
            this.imgAct.setOpacity(0);
            this.imgAct.setLocalZOrder('5');
            $('btnlayer').setLocalZOrder(6);

            this.debugRow = 0;
            this.timeAdd = 5;//20秒倒计时
            this.actCard = new Card();//$("actCard");
            this.addChild(this.actCard);
            this.showCard = new Card();
            //this.nOpenOutLayer.addChild(this.showCard);
            this.playersInfo.addChild(this.showCard);
            this.isReady = false;
            this.btReady = $('btnlayer.btReady');
            this.btJiesuan = $('btnlayer.btJiesuan');
            this.rect_bg = $('btnlayer.rect_bg');
            this.btReady.setVisible(false);
            this.btJiesuan.setVisible(false);
            this.rect_bg.setVisible(false);
            this.btSetting = $('btSetting');
            this.btSetting.setVisible(false);
            this.btnChangebg = $('btn_changebg');
            this.btnChangebg.setVisible(false);
            this.btn_control_btns = $('btn_control_btns');
            this.tipLine = $('tipLine');
            this.tipLine.setVisible(false);

            this.safenode = $('safenode');
            this.safebtn = $('safebtn', that.safenode);
            this.safebtn.setVisible(false);
            this.safenode.setLocalZOrder(5);

            this.clearRoom();

            /**
             * 切换牌背
             * @protected
             */
            eventManager.addListener(EventKey.ChangeTable, this.changeCardSize.bind(this), this);
            /**
             * 切换胡资源
             * @protected
             */
            eventManager.addListener(EventKey.ChangeHu, this._onChanageBtnRes.bind(this), this);

            TouchUtil.setOnclickListener(this.btReady, function () {
                // that.onReady();
                if (mRoom.curRound == mRoom.rounds || gameData.jiesanSucess) {
                    that.showRoomClean();
                    // console.log("meiyoujinlai")
                    if (gameData.jiesanSucess)
                        gameData.jiesanSucess = false;
                } else {
                    that.onReady();
                }
            }, {});
            TouchUtil.setOnclickListener(this.btJiesuan, function () {
                that.onJiesuan();
            }, {});
            TouchUtil.setOnclickListener(this.btSetting, function () {
                // var settinglayer = new ThemeSetting(false, 'paohuzi', that);
                // that.addChild(settinglayer);
                showWindow('SettingWindow', Setting_TYPE.Table_Hz);
            }, {});

            var id = cc.sys.localStorage.getItem('sceneid') || 0;
            // that.changeCardImg(bgArr[id], id);
            that.setCardBackImg(bgArr[id]);
            that.changeBg(id);
            TouchUtil.setOnclickListener(this.btnChangebg, function () {
                (function () {
                    i++;
                    if (i > bgArr.length) {
                        i = 1;
                    }
                    that.changeBg(i - 1);
                    that.setCardBackImg(bgArr[i - 1]);
                    // that.changeCardImg(bgArr[i-1], i-1);
                    cc.sys.localStorage.setItem(i - 1, i - 1);
                })(i);
            }, {});

            //设置按钮
            TouchUtil.setOnclickListener(this.btn_control_btns, function () {
                //that.changeBtnStatus();
            }, {});
            $('btn_control_btns').setVisible(false);
            $('btn_bg').setVisible(false);
            $('btSetting').setVisible(false);
            $('chat').setVisible(false);
            $('jiesan').setVisible(false);
            TouchUtil.setOnclickListener($('jiesan'), function () {

                // network.sendPhz(5000, "Vote/quit/1/0/0");
                // 申请投票解散
                var fun1 = function () {
                    if (window.inReview)
                        network.sendPhz(5000, 'Vote/quit/1/0/0');
                    else
                        showMessageBox('确定要申请解散房间吗？', function () {
                            network.sendPhz(5000, 'Vote/quit/1/0/0');
                        }, null, false, true, true, res.tip_mark_sqjs, res.tip_icon_default);
                };
                //房主解散房间
                var fun2 = function () {
                    if (window.inReview)
                        network.sendPhz(3003, 'Discard/' + gameData.roomId);
                    else
                        showMessageBox('解散房间不扣房卡，是否确定解散？', function () {
                            network.sendPhz(3003, 'Discard/' + gameData.roomId);
                        }, null, false, true, true, res.tip_mark_sqjs, res.tip_icon_default);
                };

                //其他玩家退出房间
                var func3 = function () {
                    showMessageBox('确定要退出房间吗?', function () {
                        network.sendPhz(3003, 'Quit/' + gameData.roomId);
                    }, null, false, true, true, res.tip_mark_exitroom, res.tip_icon_exitroom);
                };

                if (mRoom.isStart) {
                    fun1();
                } else {
                    if (mRoom.ownner == gameData.uid) {
                        fun2();
                    } else {
                        func3();
                    }
                }

            }, {});

            this.battery = $('battery');
            this.wifi = $('wifi');

            this.listActBtn = [];
            for (i = 1; i < 5; i++) {
                (function (i) {
                    var bt = $('nAction.bt' + i);
                    var rotation = $('btn_rotation', bt);
                    if (rotation) {
                        rotation.runAction(cc.repeatForever(cc.rotateBy(3, 360)));
                    }
                    bt.setTag(i);
                    if (i == 1) {
                        // var ccsScene = ccs.load("res/PhzHuAni.json", "res/");
                        // var huani = ccsScene.node;
                        // huani.setPosition(cc.p(bt.getContentSize().width / 2, bt.getContentSize().height / 2 - 10));
                        // bt.addChild(huani);
                        // huani.runAction(ccsScene.action);
                        // ccsScene.action.play('action', true);
                    }

                    TouchUtil.setOnclickListener(bt, function () {
                        that.onActionBtn(i, bt);
                    }, {});
                    that.listActBtn.push(bt);
                })(i);
            }

            mRoom.scoreInfo = {};
            mRoom.isPause = false;


            this.round = 0;
            mRoom.curRound = this.round;
            gameData.curRound = this.round;

            this.initChatBtn();
            var btn_mic = $('btn_mic');
            this.btn_mic = btn_mic;
            btn_mic.setVisible(false);
            //跑马灯
            // this.speaker = $('speaker');
            // this.speaker.setVisible(false);

            if (this._reconnectData) {
                // cc.log("room resume ==============");
                // this.clearRoom();
                if (this._reconnectData.LeftCardCount < 80) {
                    //断线重连  如果游戏还没开始，则隐藏解散按钮
                    this.showControlBtns();
                }

                mRoom.resumeRoom(this, this._reconnectData);

                if (this.isErrenwanSipai()) {
                    if (!!this['open2'])
                        this['open2'].setVisible(this._reconnectData.GameStatus == 1);
                }

                var status = this._reconnectData['GameStatus'] + 1 || ROOM_STATE_CREATED;
                if (status == ROOM_STATE_ENDED) {
                    this.setRoomState(ROOM_STATE_ENDED);
                }
                else {
                    this.setRoomState(status);
                }

                this.setPosition2Player();
            } else {
                this.setRoomState(ROOM_STATE_CREATED);
            }
            this.txtRoom.setString(gameData.roomId);
            var parts = decodeURIComponent(mRoom.wanfa).split(',');
            //parts.splice(1, 1);//去掉耒阳字牌
            var regx = new RegExp('\\,', 'g');
            var wanfa_str = (parts.length ? parts.join(',') : '');
            var content = wanfa_str.replace(regx, ' ');
            this.txtRoomId.setString(decodeURIComponent(content));
            this.txtRoomId.setVisible(true);
            this.setupPlayers();
            // cc.eventManager.removeAllListeners();//清楚监听事件
            // 暂时不用 CustomListener了。
            // for (var k in P) {
            //     cc.eventManager.removeCustomListeners(P[k]);
            // }
            //客户端状态变更
            this.addListener(P.GS_StatusChange, this.onStatusChange.bind(this));
            //开始游戏，之后发牌
            this.addListener(P.GS_GameStart, this.onGameStart.bind(this));
            //发牌
            this.addListener(P.GS_CardDeal, this.onCardDeal.bind(this));
            // this.addListener(P.GS_RoomInfo, this.onResumeRoom.bind(this));
            this.addListener(P.GS_UserJoin, this.onUserJoin.bind(this));
            //玩家临时掉线，真正掉线采用
            this.addListener(P.GS_UserDisconnect, this.onUserDisconnect.bind(this));
            //房间内断开重连
            this.addListener(P.GS_Login, this.onRoleLoginOK.bind(this));
            //离开房间
            this.addListener(P.GS_UserLeave, this.onLeaveOK.bind(this));

            // this.addListener(P.GS_UserJoin, this.onJoinOK.bind(this));
            //到谁出牌了，开始读秒
            this.addListener(P.GS_GameTurn_Out, this.onTurnOut.bind(this));
            //请客户端选择是否进牌
            this.addListener(P.GS_GameTurn_In, this.onTurnIn.bind(this));
            // 广播
            this.addListener(P.GS_BroadcastAction, this.onBroadCast.bind(this));
            //服务器宣布游戏结束
            this.addListener(P.GS_GameOver, this.onGameOver.bind(this));
            //投票广播
            this.addListener(P.GS_Vote, this.onGameVote.bind(this));
            // //聊天广播
            // this.addListener(P.GS_Chat, this.onVoice.bind(this));

            this.addListener(P.GS_Marquee, this.onMaDeng.bind(this));
            //房间结算
            this.addListener(P.GS_RoomResult, this.onRoomResult.bind(this));
            //号被顶
            this.addListener(P.GS_UserKick, this.onUserKick.bind(this));

            this.addListener(P.GS_Niao_Status, this.onNiao_Status.bind(this));

            //广播三个玩家的举手状态，在每一轮开始的时候广播
            this.addListener(P.GS_Jushou_Status, this.onJushou_Status.bind(this));

            this.addListener(P.GS_Pls_Disconnect, this.Pls_Disconnect_MSG.bind(this));
            this.addListener(P.GS_Baojing_Status, this.onBaojing.bind(this));
            this.addListener(P.GS_Fanxing_Status, this.onFanXing.bind(this));
            this.addListener(P.GS_Wangdiao_status, this.onWangdiao.bind(this));

            eventManager.addListener(EVENT_CLEAN_ROOM, this.beginReplay.bind(this), this);
            eventManager.addListener(EVENT_EATCARD, this.onEatCard.bind(this), this);
            eventManager.addListener(EVENT_EATOVER, this.hideReplayAction.bind(this), this);

            //听牌提示 99
            this.addListener(P.GS_TingPai_List, this.setTingPaiList.bind(this));
            //听牌提示 98
            this.addListener(P.GS_TishiPai_List, this.setTishiList.bind(this));

            //玩家准备状态
            this.addListener(P.GS_ReadyStatus, this.setPlayersStatus.bind(this));
            //网络连接断开
            this.addListener(P.GS_NetWorkClose, this.NetWorkCloseFunc.bind(this));
            //切home
            this.addListener('game_on_hide', this.Game_On_Hide.bind(this));
            this.addListener('game_on_show', this.Game_On_Show.bind(this));

            //所有界面已经初始化好了。
            eventManager.addListener(EventKey.ROOM_BOARD_TRANSITION_OVER, this._roomBoardTransitionOver.bind(this), this);

            this.onTimer(false);
            if (!mRoom.isReplay) {
                this.schedule(this.onTimer, 1);
            }
            this.onBattery();
            this.schedule(this.onBattery, 60);

            this.refreshTime();
            this.schedule(this.refreshTime, 1);

            this.txtUserName0.setString(ellipsisStr(gameData.nickname, 5));
            // 设置自己头像
            this.setPlayerAvator(0, gameData.headimgurl);
            mRoom.isClean = false;


            if (mRoom.isReplay) {
                this.beginReplay();
                this.playernacklayer = new PlayerBackLayer();
                this.playernacklayer.setName('playernacklayer');
                this.addChild(this.playernacklayer);
                this.playernacklayer.setData(this);
            }

            if (mRoom.isReplay == true) {
                this.btSetting.setVisible(false);
            }
            console.log('=====onCCSLoadFinish======10');
            //设置背景图
            var scene_bg_id = cc.sys.localStorage.getItem('sceneid') || 0;
            this.changeBg(scene_bg_id);
            // if(this._reconnectData){
            //     //断线重连解散房间
            //     if(this._reconnectData.Vote && this._reconnectData.Vote.Users){
            //         if(mRoom.isPause != true){
            //             var vote = new PhzRoomQuit();
            //             vote.setTag(111);
            //             this.addChild(vote);
            //             for(var i=0;i<this._reconnectData.Vote.Users.length;i++){
            //                 if(this._reconnectData.Vote.Users[i].Content != ""){
            //                     var content = this._reconnectData.Vote.Users[i].UserID + "/Vote/quit/"+ this._reconnectData.Vote.Users[i].Content +"/0/0";
            //                     if(this._reconnectData.Vote.ByWho == this._reconnectData.Vote.Users[i].UserID) {
            //                         vote.setData(content, true, this);
            //                     }
            //                 }
            //             }
            //             for(var i=0;i<this._reconnectData.Vote.Users.length;i++){
            //                 if(this._reconnectData.Vote.Users[i].Content != ""){
            //                     var content = this._reconnectData.Vote.Users[i].UserID + "/Vote/quit/"+ this._reconnectData.Vote.Users[i].Content +"/0/0";
            //                     if(this._reconnectData.Vote.ByWho != this._reconnectData.Vote.Users[i].UserID){
            //                         vote.setData(content, false, this);
            //                     }
            //                 }
            //             }
            //         }
            //     }
            // }
            //this.showSafeTipLayer(false);
            for (var i = 1; i <= 3; i++) {
                var safe_line = $('safe_line' + i, this.safenode);
                safe_line.setOpacity(255);
                safe_line.setVisible(false);
            }

            this.panelResult = $('PanelResult');
            this.panelResult.setLocalZOrder(10);
            this.panelResult.setVisible(false);
            this.checkResult = $('PanelResult.btn_result_bg.checkResult');
            this.checkResultbg = $('PanelResult.btn_result_bg.checkResultbg');
            this.showTable = $('PanelResult.btn_result_bg.showTable');
            this.showTablebg = $('PanelResult.btn_result_bg.showTablebg');
            this.continue = $('PanelResult.continue');

            this.tingNode = $('ting_node');


            TouchUtil.setOnclickListener(this.checkResult, function () {
                // that.showTablebg.setVisible(false);
                // that.checkResultbg.setVisible(true);
                that.setVisible(true);

                that.showGameResult(false);
            });
            TouchUtil.setOnclickListener(this.showTable, function () {
                // that.checkResultbg.setVisible(false);
                // that.showTablebg.setVisible(true);
                // that.setVisible(false);
                that.setVisible(true);

                that.showGameResult(false);
            });
            TouchUtil.setOnclickListener(this.continue, function () {
                if (mRoom.isReplay) {
                    mRoom.isReplay = false;
                    clearInterval(mRoom.interval);
                    gameData.roomId = 0;
                    //cc.eventManager.removeAllListeners();

                    showBoard('HallBGS_ReadyStatusoard');
                } else {
                    that.showRoomClean();
                    that.onReady(true);
                }
            });
            network.start();

            this._willShowAssist = true;
        },
        addListener: function (code, listener) {
            if (mRoom.isReplay) {
                if (code == P.GS_GameStart
                    || code == P.GS_CardDeal
                    || code == P.GS_GameTurn_In
                    || code == P.GS_GameOver
                    || code == P.GS_BroadcastAction
                ) {
                    eventManager.addListener(code, listener, this);
                }
            } else {
                network.addListener(code, listener, this);
            }
        },

        isErrenwanSipai: function () {
            if (mRoom.sipai)
                return mRoom.sipai;
            else {
                cc.log('isErrenwanSipai:', mRoom.sipai, mRoom.wanfa);
            }
            return (mRoom.wanfa && mRoom.wanfa.indexOf('发三家牌') >= 0) ? true : false;
        },
        getRoomState: function () {
            return roomState;
        },
        setRoomState: function (state) {
            roomState = state;

            cc.log('roomState:', roomState);

            eventManager.dispatchEvent(EventKey.ClubRoomStateChange, roomState);
        },
        setPosition2Player: function () {
            var playerNum = gameData.playerNum || 3;
            var players;
            if (gameData.players)
                players = gameData.players;
            else if (this._reconnectData)
                players = this._reconnectData.Players || this._reconnectData.Users;

            for (var i = 0, j = 0; i < players.length; i++, j++) {
                var offset = this.getUserIndexByUid(players[i].UserID || players[i].ID) - mRoom.getUserIndex();
                if (offset < 0) {
                    offset += playerNum;
                }
                var k = {
                    4: {'0': 0, '1': 1, '2': 2, '3': 3},
                    3: {'0': 0, '1': 1, '2': 2},
                    2: {'0': 0, '1': 1}
                }[playerNum][offset % playerNum];

                position2playerArrIdx[k] = i;
            }
            cc.log('setPosition2Player ... position2playerArrIdx = ', position2playerArrIdx);
        },
        getUserIndexByUid: function (userId) {
            var users = gameData.players;
            if (users == null) return 0;
            for (var i = 0; i < users.length; i++) {
                if (users[i].ID == userId) {
                    return i;
                }
            }
            return 0;
        },

        hideControlBtns: function () {
            $('btn_bg').setVisible(false);
            $('btSetting').setVisible(false);
            $('chat').setVisible(false);
            $('jiesan').setVisible(false);
            $('btn_changebg').setVisible(false);
            this.safebtn.setVisible(false);
        },
        showControlBtns: function () {
            //$('btn_bg').setVisible(false);
            $('btSetting').setVisible(true);
            $('chat').setVisible(true);
            $('jiesan').setVisible(true);
            $('btn_changebg').setVisible(true);
            this.safebtn.setVisible(true);
            //$('btn_control_btns').setVisible(true);
            //$('btn_control_btns').setFlippedY(true);
        },

        changeBtnStatus: function () {
            $('btn_bg').setVisible(!$('btn_bg').isVisible());
            $('btSetting').setVisible(!$('btSetting').isVisible());
            $('chat').setVisible(!$('chat').isVisible());
            $('jiesan').setVisible(!$('jiesan').isVisible());
            $('btn_control_btns').setFlippedY(!$('btn_control_btns').isFlippedY());
        },
        //更换背景时更换牌背
        setCardBackImg: function (bgArr) {
            for (var i = 0; i < this.playersNum; i++) {
                if (mRoom.shouxing) {
                    if (i == 3)
                        continue;
                }
                var open = this['open' + i];
                var openChileren = open.getChildren();
                for (var j = 0; j < openChileren.length; j++) {
                    if (openChileren[j] && _.isFunction(openChileren[j].resetCardBackImg))
                        openChileren[j].resetCardBackImg(bgArr[0]);
                }
                var out = this['out' + i];
                var outChileren = out.getChildren();
                for (var j = 0; j < outChileren.length; j++) {
                    if (outChileren[j] && _.isFunction(outChileren[j].resetCardBackImg))
                        outChileren[j].resetCardBackImg(bgArr[0]);
                }
            }
            // 剩余张数的牌背更换牌背
            // $("game_zhang.imgCardBg").setTexture('');
        },
        changeCardImg: function (arr, i) {
            if (i == 0) {
                if (arr[2])
                    this.imgCardBg.setTexture(huzi.resPath+'dynamicRes/' + arr[2] + '.png');
            } else {
                if (arr[2])
                    this.imgCardBg.setTexture(huzi.resPath+'dynamicRes/' + arr[2] + '.png');
            }
        },
        getLeiyangSipai: function (data) {
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                if (item['cmd'] == 105) {
                    if (item['data'] && item['data'].Sipai) {
                        gameData.Sipai = item['data'].Sipai;
                        return;
                    }
                }
            }
        },
        nextRoundPlay: function (isNext) {
            var that = this;

            var func = function (data) {
                hideLoading();

                if (isNext)
                    gameData.recordIds[1]++;
                else
                    gameData.recordIds[1]--;

                mRoom.isReplay = true;
                mRoom.replayData = new ReplayData(JSON.parse(data));
                mRoom.replayData.round = gameData.recordIds[1];

                var newdata = JSON.parse(data);
                var option = newdata[0].data.Option;
                var obj = JSON.parse(option);
                gameData.roomId = newdata[0].data.RoomID;
                that.getLeiyangSipai(newdata);
                mRoom.replayTime = newdata[1].data.StartTime;
                mRoom.getWanfa(obj);
                // var maLoadingLayer = new MaLoadingLayer(null, "paohuzi");
                // that.addChild(maLoadingLayer);
                // enterGame(null,'paohuzi');
                SubUpdateUtil.showGameScene(newdata, ROOM_DATA_TYPE.REPLAY);

            };
            var recordId = gameData.recordIds[0] + '-' + (!isNext ? (gameData.recordIds[1] - 1) : (gameData.recordIds[1] + 1));
            showLoading('正在获取下一局回放');
            var replayurl = app.recordPath[1] + '/' + app.recordPath[2];
            console.log('replayurl + recordId = ' + replayurl + recordId);
            http.get(replayurl + recordId, function (data) {
                hideLoading();
                func(data);
            }, function () {
                http.get('http://game-general.oss-cn-hangzhou.aliyuncs.com/leiyang-rec/' + recordId, function (data) {
                    hideLoading();
                    func(data);
                }, function () {
                    that.onReady();
                    that.beginReplay();
                    that.playernacklayer.resumeReplay();
                    hideLoading();
                    showMessageBox('获取回放失败, 请重试');
                });
            });
        },
        //改变桌面背景图
        changeBg: function (sceneid) {
            if (sceneid > 3) {
                sceneid = 0;
            }
            cc.sys.localStorage.setItem('sceneid', sceneid);
            $('bg').loadTexture(huzi.resPath+'dynamicRes/' + 'table_back' + sceneid + '.jpg');

            if (this.isErrenwanSipai()) {
                if (this.open2bg) {
                    this.open2bg.setTexture(huzi.resPath+'dynamicRes/' + bgArr[sceneid][3] + '.png');
                }
            }
        },

        // changePai:function (id) {
        //     cc.spriteFrameCache.removeSpriteFramesFromFile('res/pai.plist');
        //     cc.spriteFrameCache.removeSpriteFramesFromFile('res/pai_p.plist');
        //     cc.spriteFrameCache.removeSpriteFramesFromFile('res/pai_y.plist');
        //     cc.spriteFrameCache.addSpriteFrames(res['pai' + paibeiid + 'plist']);
        // },
        // // 注册自定义事件
        // addCustomListener: function (type, func) {
        //     return cc.eventManager.addCustomListener(type, func);
        // },
        // 删除自定义事件
        // removeListener: function () {
        //     for (var i = 0; i < this._listener.length; i++) {
        //         cc.eventManager.removeListener(this._listener[i]);
        //     }
        // },

        addCustomListener: function (type, func) {
            if (!this._listeners) {
                this._listeners = [];
            }
            var listener = cc.eventManager.addCustomListener(type, func);
            this._listeners.push(listener);
            return listener;
        },
        removeAllCustomListeners: function () {
            if (!this._listeners) {
                this._listeners = [];
            }
            for (var i = 0; i < this._listeners.length; i++) {
                cc.eventManager.removeListener(this._listeners[i]);
            }
        },


        //GPS 提示
        showSafeTipLayer: function (_bool) {
            var visible = _bool;
            if (mRoom.isReplay) visible = false;
            var that = this;
            //this.safenode.setVisible(visible);
            var safebtn = $('safebtn', that.safenode);
            var safe_gps = $('safebtn.safe_gps', that.safenode);
            var safe_gps2 = $('safebtn.safe_gps2', that.safenode);
            safe_gps.setVisible(true);
            safe_gps2.setVisible(true);
            if (_bool) {

                if (!that.isTouchedSafeBtn) {
                    safe_gps.runAction(cc.repeatForever(cc.sequence(cc.fadeIn(0.5), cc.fadeOut(0.5))));
                    safe_gps2.runAction(cc.repeatForever(cc.sequence(cc.fadeOut(0.5), cc.fadeIn(0.5))));
                } else {
                    safe_gps.setOpacity(255);
                    safe_gps2.setOpacity(255);
                    safe_gps.stopAllActions();
                    safe_gps2.stopAllActions();
                    safe_gps.setVisible(true);
                    safe_gps2.setVisible(false);
                }

            } else {
                safe_gps.setVisible(false);
                safe_gps2.setVisible(true);
            }

            TouchUtil.setOnclickListener(safebtn, function () {
                showWindow('PlayerInfoLocationWindow', false, that);
                return;
                that.isTouchedSafeBtn = true;
                safe_gps.setOpacity(255);
                safe_gps2.setOpacity(255);
                safe_gps.stopAllActions();
                safe_gps2.stopAllActions();
                if (that.needBaojing) {
                    safe_gps.setVisible(true);
                    safe_gps2.setVisible(false);
                }
                else {
                    safe_gps.setVisible(false);
                    safe_gps2.setVisible(true);
                }
                var posArr = {pos0: that.pos0, pos1: that.pos1, pos2: that.pos2, pos3: that.pos3};
                var safelayer = new SafeTipLayer(that, posArr);
                safelayer.setName('safelayer');
                that.addChild(safelayer, 10);
            });

        },

        //GPS 提示信息
        addGpsTip: function (pos, name, loc) {
            var that = this;
            // var loc = '0.000001,0.00001';
            // gameData.location = '0.000001,0.00001';
            // console.log(pos+"?????????????=="+name+"==");
            var safelayer = this.getChildByName('safelayer');
            if (safelayer) {
                var posArr = {pos0: this.pos0, pos1: this.pos1, pos2: this.pos2, pos3: this.pos3};
                safelayer.setPlayerJuli(posArr);
            }
            if (loc == undefined || loc == null || loc == 'false' || loc == false) {
                return;
            }
            var templocation1 = loc.split(',');
            var otherpeoplelocationlat = 0;
            var otherpeoplelocationlng = 0;
            if (templocation1.length == 2) {
                otherpeoplelocationlat = templocation1[0];
                otherpeoplelocationlng = templocation1[1];
            }

            var mylocationlat = LocationUtil.latitude;
            var mylocationlng = LocationUtil.longitude;
            if (!mylocationlat || !mylocationlng)
                return;
            // if (gameData.location && gameData.location.length > 0) {
            //     var templocation2 = gameData.location.split(',');
            //     if (templocation2.length == 2) {
            //         mylocationlat = templocation2[1];
            //         mylocationlng = templocation2[0];
            //     }
            // }
            var juli = '';
            var distance = LocationUtil.getFlatternDistance(mylocationlat, mylocationlng, otherpeoplelocationlat, otherpeoplelocationlng);
            if (distance <= 100) {
                juli = '玩家[' + name + ']' + '距您距离过近（' + distance + '米）';

                var safe_line = $('safe_line' + pos, this.safenode);
                if (safe_line) {
                    if (this.safenode.nodeNum == undefined || this.safenode.nodeNum == null) {
                        this.safenode.nodeNum = 0;
                    }
                    safe_line.setOpacity(255);
                    safe_line.setVisible(true);
                    if (!safe_line.pos) {
                        this.safenode.nodeNum += 1;
                        //safe_line.setPositionY(-80 + (this.safenode.nodeNum - 1) * 40);
                        // console.log(pos + "==="+ safe_line.getPositionY());
                    }
                    safe_line.pos = true;
                    var tip = safe_line.getChildByName('tip');
                    tip.setString(juli);
                    safe_line.runAction(cc.sequence(
                        cc.delayTime(10),
                        cc.fadeOut(1),
                        cc.callFunc(function () {
                            safe_line.pos = false;
                            safe_line.setVisible(false);
                            if (that.safenode.nodeNum > 0) that.safenode.nodeNum -= 1;
                        })
                    ));
                }
            }
        },
        //断网
        NetWorkCloseFunc: function () {
            //cc.eventManager.removeAllListeners();
            gameData.errMessage = '无法连接网络,请检查';
        },
        // 切home 切出游戏
        Game_On_Hide: function () {
            var msg = JSON.stringify({
                roomid: gameData.roomId, type: 'user_leave',
                content: '有事离开，等我一下', from: gameData.uid
            });
            network.sendPhz(5000, 'Say/' + msg);
        },
        // 回到游戏
        Game_On_Show: function () {
            var msg = JSON.stringify({
                roomid: gameData.roomId, type: 'user_back',
                content: '我回来了', from: gameData.uid
            });
            network.sendPhz(5000, 'Say/' + msg);
        },
        chatFunc: function (sender, type) {
            var that = this;
            // var chatLayer = new ChatLayer('paohuzi');
            // that.addChild(chatLayer);
            showWindow('ChatWindow');
        },
        //
        _roomBoardTransitionOver: function () {
            ;
        },
        //下一局（打完一局 下一局即"第xxx局"飞的动画）
        playNextJu: function () {
            eventManager.dispatchEvent(EventKey.ClubRoomGameStart);
            this.setRoomState(ROOM_STATE_ONGOING);
            // this.onUserJoin();
            var nextju = new cc.Sprite(res.nextju_png);
            nextju.setPosition(cc.p(1280 / 2, 350));
            this.addChild(nextju);
            var ju = new cc.LabelBMFont('', res.jushu_fnt);
            ju.setScale(1.3);
            ju.setPosition(cc.p(353 / 2, 78 / 2));
            ju.setString(this.round);
            nextju.addChild(ju);
            nextju.setScale(0);
            nextju.runAction(cc.sequence(
                cc.scaleTo(0.2, 0.8, 1.2),
                cc.scaleTo(0.16, 1.1, 0.9),
                cc.scaleTo(0.1, 0.95, 1.05),
                cc.scaleTo(0.1, 1, 1),
                cc.spawn(cc.moveTo(0.4, cc.p(this.txtRound.getPositionX() - 20, this.txtRound.getPositionY() + 10)), cc.scaleTo(0.4, 0)),
                cc.removeSelf()
            ));
        },
        //手机滑动动画
        fingerAni: function (isShow) {
            var fingerAni = this.getChildByName('showAni');
            if (fingerAni == null || fingerAni == undefined) {
                //var ccsScene = ccs.load("res/PhzShou.json", "res/");
                var ccsScene = ccs.load(res.PhzShou_json);
                fingerAni = ccsScene.node;
                fingerAni.setName('showAni');
                fingerAni.setPosition(cc.p(1100, 200));
                this.addChild(fingerAni);
                fingerAni.runAction(ccsScene.action);
                ccsScene.action.play('action', true);
            }
            fingerAni.setVisible(isShow);
        },
        //微信邀请好友 回调
        inviteFunc: function (type) {
            var absent = this.getShareTitleOfAbsent();
            var title = '';
            title += mRoom.getWanfaName(mRoom.wanfatype);
            title += '-' + gameData.roomId;
            title += absent;
            var regx = new RegExp('\\,', 'g');
            var parts = decodeURIComponent(mRoom.wanfa).split(',');
            parts.splice(1, 1);
            var wanfa_str = (parts.length ? parts.join(',') + ',' : '');
            var content = wanfa_str.replace(regx, '/');

            if (gameData.selectClub) {
                content = '俱乐部ID' + gameData.selectClub + '/' + content;
            }

            var shareContent = content + '速度来啊! 【丫丫衡阳字牌】';
            if (cc.sys.isNative) {
                var url = app.shareUrl + '?roomid=' + gameData.roomId;
                if (gameData.opt_conf['link'] == 1) {
                    url = 'http://www.yayayouxi.com/hengyang/?roomid=' + gameData.roomId;
                } else if (gameData.opt_conf['link'] == 2) {
                    // url = StringUtils.stringFormat(StringUtils.L('MW_URL_2'), gameData.roomId);
                    // url = StringUtils.stringFormat(StringUtils.L('MW_URL_2'), gameData.roomId, gameData.parent_area, gameData.ownerUid ^ gameData.roomId);
                    url = url
                        + '&area=' + (app.area || gameData.area || gameData.parent_area)
                        + '&sign=' + (mRoom.ownner ^ gameData.roomId)
                        + '&details=true' + '#';
                }

                console.log('===MW_URL===:' + url);

                if (type == 'weixin') {
                    WeChatUtil.shareUrl(url, title, shareContent, 0, getCurTimestamp() + gameData.uid);
                }
                else if (type == 'liaobei') {
                    LiaoBeUtil.shareUrl(url, title, shareContent, 0, getCurTimestamp() + gameData.uid);
                } else if (type = 'xianliao') {
                    XianLiaoUtil.shareGame(gameData.roomId, title, shareContent, 0, getCurTimestamp() + gameData.uid);
                }
            }
        },
        getShareTitleOfAbsent: function () {
            var absent = '';
            if (gameData.playerNum == 4) {
                if (gameData.players.length == 1) {
                    absent = '一缺三';
                }
                if (gameData.players.length == 2) {
                    absent = '二缺二';
                }
                if (gameData.players.length == 3) {
                    absent = '三缺一';
                }
                return absent;
            }
            if (gameData.playerNum == 3) {
                if (gameData.players.length == 1) {
                    absent = '一缺二';
                }
                if (gameData.players.length == 2) {
                    absent = '二缺一';
                }
                return absent;
            }
            if (gameData.playerNum == 2) {
                if (gameData.players.length == 1) {
                    absent = '一缺一';
                }
                return absent;

            }
        },
        // 复制房间号
        copyroomFunc: function (sender, type) {
            // if (!cc.sys.isNative)
            //     return;
            var sharecontent = '衡阳字牌：' + '房号: ' + gameData.roomId + ',' +
                (mRoom.wanfa ? decodeURIComponent(mRoom.wanfa) + ',' : '') +
                '速度来啊! 【衡阳字牌】';
            savePasteBoard(sharecontent);
            showMessageBox('复制房间信息成功', function () {
            });
        },
        getPlayerInfoLayer: function (i, userinfo) {
            var that = this;
            if (userinfo == null) {
                return;
            }

            if (window.inReview) //|| this.isStart == false)
                return;

            // userinfo['nickname'] = userinfo['NickName'];
            // userinfo['headimgurl'] = userinfo['HeadIMGURL'];
            // userinfo['uid'] = userinfo['ID'];
            // userinfo['ip'] = userinfo['IP'];

            //that.playerInfoLayer = new PlayerInfoLayer(userinfo, this);
            cc.log('getPlayerInfoLayer ... i: ' + i);
            if (!this._useNewProp) {
                that.playerInfoLayer = new PlayerInfoLayer(gameData.players[that['pos' + i]], this, 'phz');
                that.addChild(that.playerInfoLayer, 200);
            } else {
                that.showPlayerInfoPanel(i);
            }
            return;

            var headbg = $('node.info' + i + '.head' + i, this.playersInfo);
            TouchUtil.setOnclickListener(headbg, function () {
                if (window.inReview)
                    return;
                var scene = ccs.load(res.PlayerInfo_json);
                that.addChild(scene.node);

                var head = $('root.panel.info.head', scene.node);
                var lbNickname = $('root.panel.lb_nickname', scene.node);
                var lbId = $('root.panel.lb_id', scene.node);
                var lbIp = $('root.panel.lb_ip', scene.node);
                var male = $('root.panel.male', scene.node);
                var female = $('root.panel.female', scene.node);
                var lbAD = $('root.panel.lb_ad', scene.node);
                var lbDt = $('root.panel.lb_dt', scene.node);

                lbNickname.setString(ellipsisStr(userinfo.NickName, 6));
                loadImageToSprite(((userinfo.HeadIMGURL == null || userinfo.HeadIMGURL == '' || userinfo.HeadIMGURL == undefined)
                    ? 'res/image/defaultHead.jpg' : decodeURIComponent(userinfo.HeadIMGURL)), head);
                lbId.setString('ID: ' + userinfo.ID);
                var ip = '';
                if (userinfo && userinfo.IP) ip = userinfo.IP;
                ip = ip.split(':')[0];
                lbIp.setString('IP: ' + ip);
                male.setVisible(userinfo.sex == '1');
                female.setVisible(userinfo.sex == '2');
                if (gameData.loginType == 'yx') {
                    male.setVisible(false);
                    female.setVisible(false);
                }
                TouchUtil.setOnclickListener($('root.fake_root', scene.node), function () {
                    that.removeChild(scene.node);
                });
                TouchUtil.setOnclickListener($('root.panel', scene.node), function () {
                }, {effect: TouchUtil.effects.NONE});

                // //定位
                // console.log(userinfo);
                if (gameData.uid == userinfo.ID) {
                    if (isNullString(LocationUtil.address))
                        lbAD.setString('您可能没有开启定位权限');
                    // lbAD.setString('自己' + LocationUtil.address);
                    // else if (!gameData.location || gameData.location == '') {
                    //     lbAD.setString('您可能没有开启定位权限');
                    // }
                    else
                        lbAD.setString((LocationUtil.address));
                }
                else {
                    if (userinfo['loc'] == 'false')
                        lbAD.setString('对方' + (userinfo['locCN']));
                    else if (userinfo['loc'] == undefined || userinfo['loc'] == 'undefined' || userinfo['isOpenLocation'] == 0)
                        lbAD.setString('对方可能没有开启定位权限');
                    else
                        lbAD.setString((userinfo['locCN']));
                }
                // if (!gameData.location || userinfo['loc'] == '' || !userinfo['loc'] || userinfo['loc'] == undefined ||
                //     userinfo['loc'] == 'false' || gameData.location == 'false' || userinfo['loc'] == 'undefined'
                //     || userinfo['isOpenLocation'] == 0) {
                //     lbDt.setVisible(false);
                // }
                if (isNullString(LocationUtil.address) || isNullString(userinfo['loc']) || userinfo['isOpenLocation'] == 0) {
                    lbDt.setVisible(false);
                }
                else {
                    var templocation1 = userinfo['loc'].split(',');
                    var otherpeoplelocationlat = templocation1[0];
                    var otherpeoplelocationlng = templocation1[1];
                    // var templocation2 = gameData.location.split(',');
                    var mylocationlat = LocationUtil.latitude;
                    var mylocationlng = LocationUtil.longitude;
                    // console.log(otherpeoplelocationlat+':'+otherpeoplelocationlng+':'+mylocationlat+':'+mylocationlng);
                    if (gameData.uid == userinfo.ID)
                        lbDt.setVisible(false);
                    else
                        lbDt.setVisible(true);
                    var distance = LocationUtil.getFlatternDistance(mylocationlat, mylocationlng, otherpeoplelocationlat, otherpeoplelocationlng);
                    if (distance >= 1000) {
                        lbDt.setString('距我 ' + Math.round(distance / 1000) + '公里');
                    }
                    else {
                        lbDt.setString('距我 ' + distance + '米');
                    }

                }
            });
        },

        //手机信号发生变化
        onPing: function (dt) {
            // DC.wsPing();
            var cur = Date.now();
            var delay = cur - DC.lastPong;
            if (delay < 100) $('wifi').setTexture(huzi.res.signal5);
            else if (delay < 200) $('wifi').setTexture(huzi.res.signal4);
            else if (delay < 300) $('wifi').setTexture(huzi.res.signal3);
            else if (delay < 600) $('wifi').setTexture(huzi.res.signal2);
            else $('wifi').setTexture(res.signal1);
            if (delay > 1000 * 8) {
                // DC.closeByClient = true;
                // DC.socket.close();
                // DC.wsConnect(true);
            }
        },

        // 刷新分数
        updateScore: function (pos) {
            var users = gameData.players;
            var userIndex = this['pos' + pos];
            var userID = null;
            if (users[userIndex] && users[userIndex].ID) {
                userID = users[userIndex].ID;
                var score = mRoom.scoreInfo[userID] || 0;
                if (mRoom.wanfatype == mRoom.YOUXIAN) {
                    this['txtScore' + pos].setString('总分:' + score);
                } else {
                    this['txtScore' + pos].setString('得分:' + score);
                }
            }
        },

        //重置房间信息
        clearRoom: function (roundNotAdd) {
            for (var i = 0; i < this.playersNum; i++) {
                this['out' + i].removeAllChildren();
                this['open' + i].removeAllChildren();
                this['nCards' + i].removeAllChildren();

                if (mRoom.wanfatype == mRoom.LEIYANG) {
                    this['txtHX' + i].setString('胡子');
                    this['txtHX_value_' + i].setString('0');
                } else if (mRoom.wanfatype == mRoom.YOUXIAN || mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.MAOHUZI) {
                    this['txtHX' + i].setString('胡子');
                    this['txtHX_value_' + i].setString('0');
                } else if (mRoom.wanfatype == mRoom.WEIMAQUE) {
                    this['txtHX' + i].setString('硬息');
                    this['txtHX_value_' + i].setString('0');
                } else {
                    this['txtHX' + i].setString('胡息');
                    this['txtHX_value_' + i].setString('0');
                }
                this.hideImaAct();
            }

            this._handshuxi = undefined;
            this.actCard.setVisible(false);
            this.showCard.setVisible(false);

            if (this.isStart == true) {
                for (var i = 0; i < this.playersNum; i++) {
                    this.updateScore(i);
                }
            } else {
                this.isStart = false;
                mRoom.isStart = false;
            }

            this.secondsLeft = 0;
            this.turnPos = 0;
            this.nCards0.setVisible(false);
            this.nAction.setVisible(false);

            this.huNode.removeAllChildren();
            mAction.initGame();
            if (roundNotAdd != true) {
                if (mRoom.wanfatype == mRoom.CHEHUZI) mAction.leftCardCount = 82;//扯胡子 82张牌 2张鬼牌
                this.txtCardCount.setString(mAction.leftCardCount);
                this.round++;
            } else {
                //断线回来
                if (this.playersNum == 4) {
                    mAction.leftCardCount = 23;
                } else if (this.playersNum == 2) {
                    mAction.leftCardCount = 39;
                    if (this.isErrenwanSipai()) {
                        mRoom.sipai = true;
                    }
                    if (mRoom.sipai) {
                        mAction.leftCardCount = 19;
                    }
                } else {
                    mAction.leftCardCount = 19;
                }
                if (mRoom.wanfatype == mRoom.WEIMAQUE) mAction.leftCardCount = 22;
                if (mRoom.wanfatype == mRoom.CHEHUZI) mAction.leftCardCount = 21;
                this.txtCardCount.setString(mAction.leftCardCount);
            }
            if (mRoom.isReplay) {
                this.round = mRoom.replayData.round;
                mRoom.rounds = mRoom.replayData.rounds;
            }
            mRoom.curRound = this.round;
            gameData.curRound = this.round;

            var showTxtRound = mRoom.getRound(this.round);
            this.txtRound.setString(showTxtRound);
            this.isTurnOut = false;
            this.isTurnIn = false;
            this.gameOverHuInfo = null;

            this.Freeze = null;//冻结字段
            this.Notice = null;
        },

        onGameStart: function (event) {
            var data = event;
            this.setReady(gameData.uid, false);
            // dwz 2017-5-31 回放和创建房间游戏没开始的时候，隐藏退出和设置按钮
            this.showControlBtns();
            if (mRoom.isReplay) {
                this.hideControlBtns();
            }
            if (this.isErrenwanSipai()) {
                if (this['open2'])
                    this['open2'].setVisible(true);
            }
            this.isStart = true;
            mRoom.isStart = this.isStart;
            // 开始时重置听牌提示
            this._lastTingEvent = null;
            this.setupPlayers();
            this.setupGameStart();
            this.setZhuangjia(data.Banker);//设置庄家
            this.scheduleOnce(function () {
                this.setAllReadyVisible(false);//准备隐藏
            }, 1);
            //隐藏抓鸟
            var players = gameData.players;
            for (var i = 0; i < players.length; i++) {
                this.setSelectNiao(players[i].ID, 0, false);
                this.setNiaoNumVisible(players[i].ID, true);
            }
            //隐藏举手
            for (var i = 0; i < players.length; i++) {
                this.hideJuShou(players[i].ID, false);
            }
            //回放的得分数据
            if (mRoom.isReplay && data.Score) {
                for (var i = 0; i < data.Score.length; i++) {
                    if (!!this['txtScore' + i]) {
                        if (mRoom.wanfatype == mRoom.YOUXIAN || mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.MAOHUZI) {
                            this['txtScore' + i].setString('总分:' + data.Score[i]);
                        } else {
                            this['txtScore' + i].setString('得分:' + data.Score[i]);
                        }
                    }
                }
            }
            this.playNextJu();
        },

        setupGameStart: function () {
            this.invite.setVisible(false);
            this.invite_liaobei.setVisible(false);
            this.copyroom.setVisible(false);
            this.tuichu.setVisible(false);
            this.jiesan.setVisible(false);
            if (mRoom.isReplay != true) {
                this.btn_mic.setVisible(true);
            }
        },

        onCardDeal: function (event) {
            //断线重连回来  清理牌桌  这里局数不+1
            var that = this;
            var data = event;
            // console.log("onCardDeal");
            // console.log(data.Cards);

            this.clubTablesLayer = this.getChildByName('clubTablesLayer');
            if (this.clubTablesLayer) {
                this.clubTablesLayer.removeFromParent(true);
            }

            if (!mRoom.isReplay) {
                mRoom['CardList'] = data.Cards;
                var beforeSrotCard = deepCopy(data.Cards);
                this.clearRoom(true);
            }
            var cards = JSON.stringify(mRoom['CardList']);
            if (mRoom.isReplay) {
                var users = gameData.players;
                if (data.ToUser == users[this.pos0].ID) {
                    mRoom['CardList'] = data.Cards;
                    var cards = mRoom['CardList'];
                    cards.sort(function (a, b) {
                        return a - b;
                    });
                    var cardList = mCard.getCardList(cards);
                    this.cardList = cardList;
                    this.setupCards();
                } else if (data.ToUser == users[this.pos1].ID) {
                    mRoom['CardList1'] = data.Cards;
                    this.cardList1 = mCard.getOtherCardList(mRoom['CardList1']);
                    this.setupOtherCards(1);
                } else if (data.ToUser == users[this.pos2].ID) {
                    mRoom['CardList2'] = data.Cards;
                    this.cardList2 = mCard.getOtherCardList(mRoom['CardList2']);
                    this.setupOtherCards(2);
                } else if (data.ToUser == users[this.pos3].ID) {
                    mRoom['CardList3'] = data.Cards;
                    this.cardList3 = mCard.getOtherCardList(mRoom['CardList3']);
                    this.setupOtherCards(3);
                }
                if (this.isErrenwanSipai()) {
                    this.cardList2 = mCard.getOtherCardList(gameData.Sipai);
                    this.setupOtherCards(2);
                }
            } else {
                var cards = mRoom['CardList'];
                cards.sort(function (a, b) {
                    return a - b;
                });

                var cardList = mCard.getCardList(cards);
                this.cardList = cardList;
                cc.sys.localStorage.setItem('Storage_handsCards', JSON.stringify(this.cardList));
                this.setupCards();
                this.setReady(gameData.uid, false);
                //dwz 2017-5-31 移牌效果
                this.enableChuPai();
                return;

                // //扯胡子 收到这个消息可能是摸到癞子牌  不清理牌桌
                // if(mRoom.wanfatype == mRoom.CHEHUZI && data.Card && data.Card == 21){
                //     var cards = mRoom['CardList'];
                //     cards.sort(function (a, b) {
                //         return a - b;
                //     });
                //     this.cardList = mCard.getCardList();
                //     this.setupCards();
                // }else {
                //     //动画
                //     var beforeCardList = [];
                //     var t = [];
                //     for (var i = 0; i < beforeSrotCard.length; i++) {
                //         t.push(beforeSrotCard[i]);
                //         if (t.length == 2 || i == beforeSrotCard.length - 1) {
                //             beforeCardList.push(t);
                //             t = [];
                //         }
                //     }
                //     this.cardList = deepCopy(beforeCardList);
                //     this.setupCardWithAnmi();
                //
                //     //排序后的数组
                //     var changeIndex = function (value, xindex, yindex) {
                //         var changIndex = [0, 0];
                //         for (var s = 0; s < afterCardList.length; s++) {
                //             for (var k = 0; k < afterCardList[s].length; k++) {
                //                 if (value == afterCardList[s][k]) {
                //                     afterCardList[s][k] = 0;
                //                     changIndex[0] = s - xindex;
                //                     changIndex[1] = k - yindex;
                //                     break;
                //                 }
                //             }
                //         }
                //         return changIndex;
                //     };
                //     //重新排序
                //     var cards = mRoom['CardList'];
                //     cards.sort(function (a, b) {
                //         return a - b;
                //     });
                //     var afterCardList = mCard.getCardList();
                //     this.scheduleOnce(function () {
                //         var cardList = this.nCards0.getChildren();
                //         for (var i = 0; i < cardList.length; i++) {
                //             var card = cardList[i];
                //             var moveIndex = changeIndex(card.data, card.row, card.column);
                //             card.runAction(cc.sequence(
                //                 cc.moveBy(0.2, cc.p(moveIndex[0] * (that.cardSize.w * that.cardScale - 2),
                //                     moveIndex[1] * (that.cardSize.h * that.cardScale - 15)))
                //             ))
                //         }
                //     }, 1.3);
                //
                //     this.scheduleOnce(function () {
                //         this.cardList = mCard.getCardList();
                //         this.setupCards();
                //     }, 2);
                // }
            }
        },

        getUserPosIndex: function (userId) {
            var users = gameData.players;
            var pos = 0;
            if (mRoom.isReplay) {
                for (var i = 0; i < users.length; i++) {
                    if (userId == users[i].ID) {
                        pos = i;
                        break;
                    }
                }
            } else {
                if (userId == gameData.uid) {
                    pos = 0;
                } else if (users[this.pos1] != null && userId == users[this.pos1].ID) {
                    pos = 1;
                } else if (users[this.pos2] != null && userId == users[this.pos2].ID) {
                    pos = 2;
                } else if (users[this.pos3] != null && userId == users[this.pos3].ID) {
                    pos = 3;
                }
            }
            return pos;
        },
        getUserHeaderData: function () {
            var data = {};
            var players = gameData.players;
            var scale = cc.view.getFrameSize().width / cc.director.getWinSize().width;
            var theight = cc.view.getFrameSize().height / scale;
            var boardHeight = (theight - cc.director.getWinSize().height) / 2;
            console.log('boardHeight = ' + boardHeight);
            for (var i = 0; i < players.length; i++) {
                var player = players[i];
                var pos = this.getUserPosIndex(player.ID);
                var header = $('node.info' + pos + '.head' + pos, this.playersInfo);
                var headerPos = header.convertToWorldSpace(cc.p(0, 0));
                var width = header.getBoundingBox().width;
                var height = header.getBoundingBox().height;
                var x = headerPos.x;
                var y = headerPos.y + height - boardHeight;
                data[player.ID] = {
                    x: x,
                    y: y,
                    width: width,
                    height: height
                };
            }
            return JSON.stringify(data);
        },

        setupPlayers: function () {
            var that = this;
            that.refreshPlayersStates();

            if (this.isStart || mRoom.curRound > 1) {

                if (this.assistantLayer && cc.sys.isObjectValid(this.assistantLayer)) {
                    this.assistantLayer.removeFromParent(true);
                    this.assistantLayer = null;
                }
            }

            if (mRoom.isReplay) {
                gameData.players = mRoom.replayData.users;
            }
            var data = gameData.players || [];

            if (data.length >= this.playersNum) {
                if (this.assistantLayer && cc.sys.isObjectValid(this.assistantLayer)) this.assistantLayer.setVisible(false);
                this.invite.setVisible(false);
                this.copyroom.setVisible(false);
            } else {
                this.invite.setVisible(true);
                this.copyroom.setVisible(false);
                if (this.assistantLayer && cc.sys.isObjectValid(this.assistantLayer)) this.assistantLayer.setVisible(true);
            }

            gameData.playerMap = {};
            for (var i = 0; i < data.length; i++) {
                gameData.playerMap[data[i].ID] = data[i];
            }
            if (data.length == 3) {
                if (gameData.switchVideo) {
                    AgoraUtil.initVideoView(this.getUserHeaderData());
                    setTimeout(function () {
                        AgoraUtil.openVideo(gameData.roomId.toString(), gameData.uid.toString());
                    }, 1000);
                }
            }
            var pos = 0;
            if (mRoom.isReplay == true) {
                pos = 0;
            } else {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].ID == gameData.uid) {
                        pos = i;
                    }
                }
            }
            this.pos0 = pos;
            this.pos1 = (pos + 1) % this.playersNum;
            this.pos2 = (pos + 2) % this.playersNum;
            this.pos3 = (pos + 3) % this.playersNum;
            if (mRoom.isReplay) {
                if (data.length > this.pos1) {
                    this.txtUserName0.setString(ellipsisStr(data[this.pos0].NickName, 5));
                    this.setPlayerAvator(0, decodeURIComponent(data[this.pos0].HeadIMGURL), data[this.pos0].ID);
                    this.txtUserName0.setVisible(true);
                    this.txtHX0.setVisible(true);
                }
            }
            //报警  100以内  报警
            that.needBaojing = false;
            // gameData.location = "0.1,0.1";
            for (var i = 0; i < data.length; i++) {
                if (data[i].ID != gameData.uid) {
                    var pos = mRoom.getUserPosIndex(data[i].ID);
                    //console.log(pos+"==="+data[i].NickName);
                    //console.log("Location==="+data[i]['Location']);
                    this.addGpsTip(pos, data[i]['NickName'], data[i]['Location']);
                }
            }
            //任意两个人距离 <500 就报警
            for (var i = 0; i < data.length; i++) {
                for (var j = i + 1; j < data.length; j++) {
                    var distance = this.getJuliByLoc(data[i]['Location'], data[j]['Location']);
                    //console.log('============distance:'+distance);
                    if (distance <= 500) {
                        that.needBaojing = true;
                        break;
                    }
                }
            }
            // var safebtn = $("safebtn",that.safenode);
            // safebtn.setVisible(needBaojing);
            if (!window.inReview) {
                this.showSafeTipLayer(that.needBaojing);
            }

            if (this.playersNum == 2) {
                if (data.length > this.pos1) {
                    if (this.txtUserName1 && cc.sys.isObjectValid(this.txtUserName1)) {
                        this.txtUserName1.setString(ellipsisStr(data[this.pos1].NickName, 5));
                        this.txtUserName1.setVisible(true);
                    }
                    this.setPlayerAvator(1, decodeURIComponent(data[this.pos1].HeadIMGURL), data[this.pos1].ID);

                    if (this.txtHX1 && cc.sys.isObjectValid(this.txtHX1)) {
                        this.txtHX1.setVisible(true);
                    }
                } else {
                    if (this.txtUserName1 && cc.sys.isObjectValid(this.txtUserName1)) {
                        this.txtUserName1.setVisible(true);
                    }
                    if (this.txtHX1 && cc.sys.isObjectValid(this.txtHX1)) {
                        this.txtHX1.setVisible(false);
                    }
                    this.setPlayerAvator(1, 'hide');
                }
            }

            if (this.playersNum >= 3) {
                if (data.length > this.pos1) {
                    if (this.txtUserName1 && cc.sys.isObjectValid(this.txtUserName1)) {
                        this.txtUserName1.setString(ellipsisStr(data[this.pos1].NickName, 5));
                        this.txtUserName1.setVisible(true);
                    }
                    this.setPlayerAvator(1, decodeURIComponent(data[this.pos1].HeadIMGURL), data[this.pos1].ID);

                    if (this.txtHX1 && cc.sys.isObjectValid(this.txtHX1)) {
                        this.txtHX1.setVisible(true);
                    }
                } else {
                    if (this.txtUserName1 && cc.sys.isObjectValid(this.txtUserName1)) {
                        this.txtUserName1.setVisible(true);
                    }
                    if (this.txtHX1 && cc.sys.isObjectValid(this.txtHX1)) {
                        this.txtHX1.setVisible(false);
                    }
                    this.setPlayerAvator(1, 'hide');
                }
                if (data.length > this.pos2) {

                    if (this.txtUserName2 && cc.sys.isObjectValid(this.txtUserName2)) {
                        this.txtUserName2.setString(ellipsisStr(data[this.pos2].NickName, 5));
                        this.txtUserName2.setVisible(true);
                    }
                    if (this.playersNum > 2) {
                        this.setPlayerAvator(2, decodeURIComponent(data[this.pos2].HeadIMGURL), data[this.pos2].ID);
                    } else if (this.playersNum == 2) {
                        this.setPlayerAvator(1, decodeURIComponent(data[this.pos2].HeadIMGURL), data[this.pos2].ID);
                    }
                    if (this.txtHX2 && cc.sys.isObjectValid(this.txtHX2)) {
                        this.txtHX2.setVisible(true);
                    }

                } else {
                    if (this.txtUserName2 && cc.sys.isObjectValid(this.txtUserName2)) {
                        this.txtUserName2.setVisible(true);
                    }
                    if (this.txtHX2 && cc.sys.isObjectValid(this.txtHX2)) {
                        this.txtHX2.setVisible(false);
                    }
                    this.setPlayerAvator(2, 'hide');
                }
            }

            if (this.playersNum >= 4) {
                if (data.length > this.pos3) {
                    if (this.txtUserName3 && cc.sys.isObjectValid(this.txtUserName3)) {
                        this.txtUserName3.setString(ellipsisStr(data[this.pos3].NickName, 5));
                        this.txtUserName3.setVisible(true);
                    }
                    this.setPlayerAvator(3, decodeURIComponent(data[this.pos3].HeadIMGURL), data[this.pos3].ID);
                    if (this.txtHX3 && cc.sys.isObjectValid(this.txtHX3)) {
                        this.txtHX3.setVisible(true);
                    }
                } else {
                    if (this.txtUserName3 && cc.sys.isObjectValid(this.txtUserName3)) {
                        this.txtUserName3.setVisible(true);
                    }
                    if (this.txtHX3 && cc.sys.isObjectValid(this.txtHX3)) {
                        this.txtHX3.setVisible(false);
                    }
                    this.setPlayerAvator(3, 'hide');
                }
            }
            if (mRoom.isReplay != true) {

                if (mRoom.ownner == gameData.uid || mRoom.ownner == gameData.uid.toString()) {

                    //房主
                    this.invite.setVisible(true);
                    this.invite_liaobei.setVisible(true);
                    this.copyroom.setVisible(false);
                    this.tuichu.setVisible(false);
                    this.jiesan.setVisible(true);
                } else {
                    this.invite.setVisible(true);
                    this.invite_liaobei.setVisible(true);
                    this.copyroom.setVisible(false);
                    this.tuichu.setVisible(true);
                    this.jiesan.setVisible(false);
                }

                if (window.nativeVersion >= '4.0.0') {
                    this.invite.setVisible(false);
                    this.invite_liaobei.setVisible(false);
                    $('btnlayer.share_v4').setVisible(true);
                }
            }
            if (window.inReview) {
                this.invite.setVisible(false);
                this.invite_liaobei.setVisible(false);
                if ($('btnlayer.share_v4'))
                    $('btnlayer.share_v4').setVisible(false);
                this.copyroom.setVisible(false);
            }
            if (data.length >= this.playersNum) {
                // if (this.playersNum == 4) {
                //     mAction.leftCardCount = 23;
                // } else {
                //     mAction.leftCardCount = 19;
                // }
                // if (mRoom.wanfatype == mRoom.WEIMAQUE) mAction.leftCardCount = 22;
                // if (mRoom.wanfatype == mRoom.CHEHUZI) mAction.leftCardCount = 21;
                // this.txtCardCount.setString(mAction.leftCardCount);

                this.invite.setVisible(false);
                this.invite_liaobei.setVisible(false);
                if ($('btnlayer.share_v4'))
                    $('btnlayer.share_v4').setVisible(false);
                this.copyroom.setVisible(false);
                this.tuichu.setVisible(false);
                this.jiesan.setVisible(false);
                //this.hideControlBtns(false);
                if (mRoom.isReplay != true) {
                    this.showControlBtns();
                }
                //$('btn_control_btns').setVisible(true);
            }
            for (var i = 0; i < this.playersNum; i++) {
                if (data[this['pos' + i]]) {
                    this.updateScore(i);
                    //this.getPlayerInfoLayer(i, data[this["pos" + i]]);
                }
            }
            for (var i = 0; i < this.playersNum; i++) {
                (function (i) {
                    var headbg = $('node.info' + i + '.head' + i, that.playersInfo);
                    TouchUtil.setOnclickListener(headbg, function () {
                        if (!mRoom.isReplay) {
                            that.getPlayerInfoLayer(i, data[that['pos' + i]]);
                        }

                    });
                })(i);
            }
        },

        getJuliByLoc: function (loc, loc2) {
            var distance = 100000;
            if (loc) {
                var templocation1 = loc.split(',');
                var otherpeoplelocationlat = 0;
                var otherpeoplelocationlng = 0;
                if (templocation1.length == 2) {
                    otherpeoplelocationlat = templocation1[1];
                    otherpeoplelocationlng = templocation1[0];
                }

                var mylocationlat = 0;
                var mylocationlng = 0;
                if (loc2) {
                    var templocation2 = loc2.split(',');
                    if (templocation2.length == 2) {
                        mylocationlat = templocation2[1];
                        mylocationlng = templocation2[0];
                    }
                }
                //如果没有定位对象的话 主动断线 重新获取下2001
                if (LocationUtil == undefined) {
                    network.disconnect();
                    return;
                }
                distance = LocationUtil.getFlatternDistance(mylocationlat, mylocationlng, otherpeoplelocationlat, otherpeoplelocationlng);
            }
            return distance;
        },
        /**
         * 设置头像
         * @param pos
         * @param url
         * @param uid
         */
        setPlayerAvator: function (pos, url, uid) {
            if (!this.playersInfo || !cc.sys.isObjectValid(this.playersInfo)) {
                network.disconnect();
                return;
            }
            //头像
            var info = $('node.info' + pos, this.playersInfo);
            var headbg = $('node.info' + pos + '.head' + pos, this.playersInfo);
            if (url == 'hide') {
                headbg.setVisible(false);
                info.setVisible(false);
                return;
            } else {
                headbg.setVisible(true);
                info.setVisible(true);
            }
            if (url == undefined || url == '' || url == null) {
                url = 'res/image/defaultHead.jpg';
            }
            var avator = headbg.getChildByName('head');
            avator.setLocalZOrder(-1);
            loadImageToSprite(url, avator);//头像
        },

        setupCardWithAnmi: function () {
            this.nCards0.setVisible(true);
            this.nCards0.removeAllChildren();
            this.nCards0.setScale(1);

            var cardList = this.cardList;
            for (var i = 0; i < 2; i++) {
                for (var j = 0; j < cardList.length; j++) {
                    var card = new Card();
                    this.nCards0.addChild(card);
                    card.setData(cardList[j][i], this);
                    card.setLocalZOrder(3 - i);
                    card.setRowColumn(j, i);
                    card.setScale(this.cardScale);
                    card.setPosition(j * (this.cardSize.w * this.cardScale - 2), i * (this.cardSize.h * this.cardScale - 25) - 90);
                    card.setOpacity(0);
                    card.runAction(
                        cc.sequence(
                            cc.delayTime(i * 0.5 + j * 0.05),
                            cc.fadeIn(0.15)
                        )
                    );
                }
            }
            if (this.playersNum == 3) {
                this.nCards0.setPositionX(1280 * 0.5 - cardList.length * 0.5 * this.cardSize.w * this.cardScale + 40);
            } else {
                this.nCards0.setPositionX(1280 * 0.5 - cardList.length * 0.5 * this.cardSize.w * this.cardScale + 40);
            }
        },
        //设置自己的手牌
        setupCards: function () {
            var that = this;
            that.isMoving = true;
            that.isBeginTouch = true;

            this.nCards0.setVisible(true);
            this.nCards0.removeAllChildren();
            this.nCards0.setScale(1);

            var cardList = this.cardList || [];

            if (!!gameData.resumeRoom && this.checkCompareCards()) {
                this.cardList = JSON.parse(cc.sys.localStorage.getItem('Storage_handsCards')) || [];
                cardList = this.cardList;
            }
            gameData.resumeRoom = false;

            if (cardList == undefined) return;

            //计算手牌的胡息
            this._handshuxi = mCard.getHandsHuXi(deepCopy(cardList));
            this.updateHX(0);

            for (var i = 0; i < cardList.length; i++) {
                var cards = cardList[i];
                var isKan = false;
                var isGray = false;
                //坎 不能移动
                if (cards.length == 3 && cards[0] == cards[1] && cards[1] == cards[2]) {
                    isKan = true;
                    if (mRoom.wanfatype == mRoom.WEIMAQUE) {
                        isKan = false;
                        isGray = true;
                    }
                }
                for (var j = cards.length - 1; j >= 0; j--) {
                    var card = new Card();
                    this.nCards0.addChild(card);
                    card.setData(cards[j], this);
                    card.setRowColumn(j, i);
                    card.setKan(isKan);
                    // if (isKan == false) {
                    //     card.setSelectedCard(this.actCard);
                    // }
                    card.setLocalZOrder(3 - j);
                    //if (isGray) card.setGrayCard(isGray);
                    card.setScale(this.cardScale);
                    card.setPosition(i * (this.cardSize.w * this.cardScale - 2) - 40, j * (this.cardSize.h * this.cardScale - 25) - 10);
                    var tag = (i + 1) * 100 + j + 1;
                    card.setTag(tag);
                }
            }
            //冻结
            this.setFreezeCard(this.Freeze);
            if (this.playersNum == 3) {
                this.nCards0.setPositionX(1280 * 0.5 - cardList.length * 0.5 * this.cardSize.w * this.cardScale + 120);
                //console.log('nCards0 de popitionX:'+ this.nCards0.getPositionX());
            } else {
                this.nCards0.setPositionX(1280 * 0.5 - cardList.length * 0.5 * this.cardSize.w * this.cardScale + 120);
            }

            //重新设置
            that.scheduleOnce(function () {
                that.isMoving = false;
                that.isBeginTouch = false;
            }, 0.5);

            //如果有听牌提示且需要重新显示听，则调显示听
            if (!!that._lastTingEvent && that._needShowTingTip) {
                that.setTishiList(that._lastTingEvent);
                that._needShowTingTip = false;
            }
        },
        /**
         * 检查对比本地存的数组和 服务器数组内容是否一致
         * 只在断线重连的时候加以判断，其他情况不用
         * @returns {boolean}
         */
        checkCompareCards: function () {
            if (!cc.sys.localStorage.getItem('Storage_handsCards') || cc.sys.localStorage.getItem('Storage_handsCards') == ''
                || cc.sys.localStorage.getItem('Storage_handsCards') == []) {
                return false;
            }
            var storageCards = JSON.parse(cc.sys.localStorage.getItem('Storage_handsCards')) || [];
            var arr1 = [], arr2 = [];
            for (var i = 0; i < storageCards.length; i++) {
                var cards = storageCards[i];
                for (var j = 0; j < cards.length; j++) {
                    if (cards[j] && cards[j] != []) {
                        arr1.push(cards[j]);
                    }
                }
            }
            for (var i = 0; i < this.cardList.length; i++) {
                var cards = this.cardList[i];
                for (var j = 0; j < cards.length; j++) {
                    if (cards[j] && cards[j] != []) {
                        arr2.push(cards[j]);
                    }
                }
            }
            if (arr1.length == 0 || arr2.length == 0 || arr1.length != arr2.length) {
                cc.sys.localStorage.setItem('Storage_handsCards', []);
                console.log('=======本地存储有误111 + arr1=' + JSON.stringify(arr1) + ' arr2=' + JSON.stringify(arr2));
                return false;
            }
            arr1.sort(function (a, b) {
                return a - b;
            });
            arr2.sort(function (a, b) {
                return a - b;
            });
            for (var i = 0; i < arr1.length; i++) {
                if (arr1[i] != arr2[i]) {
                    cc.sys.localStorage.setItem('Storage_handsCards', []);
                    console.log('======本地存储有误222 + arr1=' + JSON.stringify(arr1) + ' arr2=' + JSON.stringify(arr2));
                    return false;
                }
            }
            console.log('===============本地存储正确');
            return true;
        },

        //设置其他人的手牌
        setupOtherCards: function (id) {
            if (id >= this.playersNum) {
                if (!this.isErrenwanSipai())
                    return;
                else {
                    if (!!this['open2']) {
                        this['open2'].setVisible(false);
                    }
                }
            }
            if (!this['nCards' + id])
                return;
            this['nCards' + id].setVisible(true);
            this['nCards' + id].removeAllChildren();
            this['nCards' + id].setScale(0.5);
            var cardList = this['cardList' + id];
            if (cardList == undefined || cardList == null) {
                return;
            }
            for (var i = 0; i < cardList.length; i++) {
                var cards = cardList[i];
                var isKan = false;
                //坎 不能移动
                if (cards.length == 3 && cards[0] == cards[1] && cards[1] == cards[2]) {
                    isKan = true;
                }
                for (var j = cards.length - 1; j >= 0; j--) {
                    var card = new Card();
                    this['nCards' + id].addChild(card);
                    card.setData(cards[j], this);
                    // if (isKan == false) {
                    //     card.setSelectedCard(this.actCard);
                    // }
                    card.setTouchEnableStatus(false);
                    card.setPosition(i * this.cardSize.w, j * this.cardSize.h - 80);
                    var tag = (i + 1) * 100 + j + 1;
                    card.setTag(tag);
                }
            }
        },

        //某一列添加牌
        addNewColCard: function (i, card, row, col) {
            var cardList = this.cardList;
            var addCol = 0;
            var sCards = cardList[col];

            if (i <= col) {
                addCol = 1;
            }
            if (sCards.length > 1 && cardList.length >= 10) {
                return false;
            }

            cardList.splice(i, 0, [card.data]);
            sCards.splice(row, 1);
            if (sCards.length == 0) {
                cardList.splice(col + addCol, 1);
            }
            return true;
        },

        //展示相同的牌
        setSameCardShow: function (showcard, isshow) {
            if (mRoom.isReplay) {
                return;
            }
            for (var i = 0; i < this.playersNum; i++) {
                var open = this['open' + i];
                var openChileren = open.getChildren();
                for (var j = 0; j < openChileren.length; j++) {
                    var card = openChileren[j];
                    if (card.data == showcard) {
                        card.setSelectCard(isshow);
                    }
                }
                var out = this['out' + i];
                var outChileren = out.getChildren();
                for (var j = 0; j < outChileren.length; j++) {
                    var card = outChileren[j];
                    if (card.data == showcard) {
                        card.setSelectCard(isshow);
                    }
                }
            }
            if (this.isTurnOut)
                this.tipLine.setVisible(isshow);

        },

        //移牌
        moveCard: function (card, px, py) {
            var cardList = this.cardList;
            var tag = card.getTag();
            var col = parseInt(tag / 100) - 1;
            var row = tag % 100 - 1;
            var offset = this.nCards0.getPositionX() - 50;

            var isMoved = false;
            var cardscale = 1;
            var cardWidth = this.cardSize.w * this.cardScale;
            var cardL = cardWidth * 0.5;
            var cardR = cardWidth * 0.7;
            for (var i = 0; i < cardList.length; i++) {
                var canMove = true;
                var cards = cardList[i];
                //坎上不能放牌
                if (cardList[i].length == 3 && cardList[i][0] == cardList[i][1] && cardList[i][0] == cardList[i][2]) {
                    canMove = false;
                }
                var tCard = this.nCards0.getChildByTag((i + 1) * 100 + 1);
                if (tCard != null && i != col && canMove) { //不同列之间移动
                    var cx = cardWidth * cardscale * i + offset;
                    var dis = px - cx;
                    if (dis < -cardL * cardscale && i == 0) {
                        isMoved = this.addNewColCard(i, card, row, col);
                        break;
                    } else if (dis > cardL * cardscale && i == cardList.length - 1) {
                        isMoved = this.addNewColCard(i + 1, card, row, col);
                        break;
                    } else if (dis >= -cardL * cardscale && dis <= cardL * cardscale) {
                        if (cards.length < 4) {
                            cards.push(card.data);
                            var sCards = cardList[col];
                            sCards.splice(row, 1);
                            if (sCards.length == 0) {
                                cardList.splice(col, 1);
                            }
                            isMoved = true;
                        }
                        break;
                    } else if (dis > cardL * cardscale && dis < cardR * cardscale) {
                        isMoved = this.addNewColCard(i + 1, card, row, col);
                        break;
                    }
                    // else if(dis<-cardL*cardscale){
                    //     isMoved = this.addNewColCard(i, card, row, col);
                    //     break;
                    // }
                }
                if (tCard != null && canMove) {
                    //移动 y 的
                    var cx = cardWidth * cardscale * i + offset;
                    var dis = px - cx;
                    if (dis >= -cardL * cardscale && dis <= cardL * cardscale) {
                        for (var j = 0; j < cards.length; j++) {
                            if (py >= 88 / 2 && py >= 88 * (j - 1 / 2) && py <= 88 * (j + 1 / 2)) {
                                if (cards[card.row] && cards[j]) {
                                    if (card.row > j) {
                                        var tmp = cards[j];
                                        for (var s = j; s < card.row; s++) {
                                            cards[s] = cards[s + 1];
                                        }
                                        cards[card.row] = tmp;
                                        isMoved = true;
                                    } else if (card.row < j) {
                                        var tmp = cards[card.row];
                                        for (var s = card.row; s < j; s++) {
                                            cards[s] = cards[s + 1];
                                        }
                                        cards[j] = tmp;
                                        isMoved = true;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (isMoved == true)
                this.setupCards();
        },

        removeCardInList: function (card, userPos, outCardColumn, outCardRow) {
            var cardList = userPos == 0 ? this.cardList : this['cardList' + userPos];
            if (cardList == undefined || cardList == null) {
                return;
            }
            if (outCardColumn && outCardRow) {
                for (var i = cardList.length - 1; i >= 0; i--) {
                    var cards = cardList[i];
                    for (var j = cards.length - 1; j >= 0; j--) {
                        if (i == (outCardColumn - 1) && j == (outCardRow - 1) && card == cards[j]) {
                            cards.splice(j, 1);
                            if (cards.length == 0) {
                                cardList.splice(i, 1);
                            }
                            return;
                        }
                    }
                }
            }
            for (var i = cardList.length - 1; i >= 0; i--) {
                var cards = cardList[i];
                for (var j = cards.length - 1; j >= 0; j--) {
                    if (cards[j] == card) {
                        cards.splice(j, 1);
                        if (cards.length == 0) {
                            cardList.splice(i, 1);
                        }
                        return;
                    }
                }
            }
        },

        removeCards: function (cardsToRemove, userPos, outCardColumn, outCardRow) {
            var cards = userPos == 0 ? mRoom['CardList'] : mRoom['CardList' + userPos];
            for (var i = 0; i < cardsToRemove.length; i++) {
                var deleteList = [];
                if (cards) {
                    for (var j = cards.length - 1; j >= 0; j--) {
                        if (cards[j] == cardsToRemove[i]) {
                            deleteList.push([j]);
                            break;
                        }
                    }
                }
                removeInArray(cards, deleteList);
            }
            if (cardsToRemove && cardsToRemove.length == 1 && outCardColumn && outCardRow) {
                this.removeCardInList(cardsToRemove[0], userPos, outCardColumn, outCardRow);
            } else {
                for (var i = 0; i < cardsToRemove.length; i++) {
                    this.removeCardInList(cardsToRemove[i], userPos);
                }
            }

            if (userPos == 0) {
                cc.sys.localStorage.setItem('Storage_handsCards', JSON.stringify(this.cardList));
                this.setupCards();
            } else {
                this.setupOtherCards(userPos);
            }
        },

        addCard: function (cardToAdd) {
            var cards = mRoom['CardList'];
            cards.push(cardToAdd);
            cards.sort(function (a, b) {
                return a - b;
            });

            //cards = cards.concat([cardToAdd]);
            var isAdd = false;
            for (var i = 0; i < this.cardList.length; i++) {
                var cards = this.cardList[i];
                if ((cards.length == 1 && cards[0] == cardToAdd) || (cards.length == 2 && cards[0] == cardToAdd && cards[1] == cardToAdd)) {
                    cards.push(cardToAdd);
                    isAdd = true;
                    break;
                }
            }
            if (isAdd == false) {
                this.cardList.push([cardToAdd]);
            }
            this.setupCards();
        },
        enableChuPai: function () {
            var that = this;
            var touchLayer = this.getChildByName('touchLayer');
            if (touchLayer) return;
            that._isShePao = false;

            touchLayer = new cc.LayerColor(cc.color(0, 0, 0, 0), cc.winSize.width, cc.winSize.height);
            touchLayer.setName('touchLayer');
            touchLayer.setAnchorPoint(0, 0);
            this.addChild(touchLayer);

            // var movecard = null;
            // var movecardTmp = null;
            // var positionBak = null;
            // var zorderBak = null;
            // var movetoxy = null;
            // var movetoxybak = null;
            // var movexy = null;
            // var cardsXYBak = [];
            // //移动的牌
            // var movetocardArr = [];
            // var movetocardPosArr = [];
            that.isMoving = false;
            that.isBeginTouch = false;  //禁止多点触控 禁止俩手同时点击 同时移动两张牌
            var firstCardPos = cc.p(0, 0);
            var chupaiListener = cc.EventListener.create({
                event: cc.EventListener.TOUCH_ONE_BY_ONE,
                swallowTouches: true,
                onTouchBegan: function (touch, event) {
                    // if ($('resultLayer').isVisible() || $("gameResultLayer").isVisible()) {
                    //     return false;
                    // }
                    //ios 拉起系统菜单 吞噬 touchend事件  导致 卡死
                    try {
                        if (movecard && positionBak && (that.isBeginTouch)) {
                            if (movetocardArr && movetocardArr.length > 0) {
                                for (var n = 0; n < movetocardArr.length; n++) {
                                    movetocardArr[n].stopAllActions();
                                    movetocardArr[n].runAction(cc.sequence(
                                        cc.moveTo(0.1, movetocardPosArr[n])
                                    ));
                                }
                            }
                            movetocardArr = [];
                            movetocardPosArr = [];

                            if (zorderBak) movecard.setLocalZOrder(zorderBak);
                            movecardTmp.setVisible(false);
                            movecard.stopAllActions();
                            movecard.setPosition(movecardTmp.getPosition());
                            movecard.setOpacity(255);
                            movecard.runAction(cc.sequence(
                                cc.moveTo(0.1, positionBak),
                                cc.callFunc(function (sender) {
                                    that.isMoving = false;
                                    that.isBeginTouch = false;
                                    sender = null;
                                })
                            ));
                            return;
                        }
                        //console.log("testtttttt====" + that.isBeginTouch);
                        if (that.isBeginTouch) {
                            return;
                        }
                        if (that.nCards0.getChildByTag(101)) firstCardPos = that.nCards0.getChildByTag(101).getPosition();
                        cardsXYBak = [];
                        for (var i = 0; i < that.cardList.length; i++) {
                            if (cardsXYBak[i] == null) cardsXYBak[i] = [];
                            for (var j = 0; j < that.cardList[i].length; j++) {
                                if (cardsXYBak[i][j] == null) cardsXYBak[i][j] = {};
                                cardsXYBak[i][j] = {card: that.cardList[i][j], x: i, y: j, tag: (i + 1) * 100 + j + 1};
                            }
                        }
                        var cardSprites = that.nCards0.getChildren();
                        for (var i = 0; i < cardSprites.length; i++) {
                            if (TouchUtil.isTouchMe(cardSprites[i], touch, event, null)) {
                                movecard = cardSprites[i];
                                // cc.log('----------------A: cardSprites' + movecard.data);
                                movexy = {x: movecard.column, y: movecard.row};
                                //坎不能出
                                if (that.cardList && that.cardList[movecard.column] &&
                                    // that.cardList[movecard.column].length == 3 &&
                                    that.cardList[movecard.column][0] == that.cardList[movecard.column][1] &&
                                    that.cardList[movecard.column][0] == that.cardList[movecard.column][2] &&
                                    that.cardList[movecard.column][0] != 21) {
                                    if (movexy.y < 3) {
                                        movecard = null;
                                        movexy = null;
                                        return false;
                                    }
                                }
                                zorderBak = movecard.getLocalZOrder();
                                positionBak = movecard.getPosition();
                                movecard.setOpacity(0);
                                // this.movecard = movecard;
                                // this.positionBak = positionBak;
                                movecardTmp = that.nCards0.getChildByName('movecardTmp');
                                if (movecardTmp == null || movecardTmp == undefined) {
                                    movecardTmp = new Card();
                                    movecardTmp.setName('movecardTmp');
                                    that.nCards0.addChild(movecardTmp);
                                }
                                movecardTmp.setLocalZOrder(10);
                                movecardTmp.setData(movecard.data, null, 0);
                                movecardTmp.setVisible(true);
                                movecardTmp.setRowColumn(movecard.row, movecard.column);
                                movecardTmp.setPosition(movecard.getPosition());
                                if (movecard.getChildByName('tingmark') && cc.sys.isObjectValid(movecard.getChildByName('tingmark'))
                                    && movecard.getChildByName('tingmark').isVisible()) {
                                    movecardTmp.setTingMark(true);
                                    movecard.getChildByName('tingmark').setOpacity(0);
                                }

                                that.setSameCardShow(movecard.data, true);//选中相同颜色的

                                //console.log("beginnnnnn");
                                that.isBeginTouch = true;
                                try {
                                    if (tishiData && tishiData.length > 0) {
                                        for (var k = 0; k < tishiData.length; k++) {
                                            if (tishiData[k]['Card'] == movecard.data) {
                                                that.showTingPaiOnDesk(tishiData[k]['TingCards'], 'touchMove');
                                                break;
                                            }
                                        }
                                    }
                                } catch (e) {
                                    showMessageBox('e : ' + e.toString());
                                }
                                return true;
                            }
                        }
                        return false;
                    } catch (e) {
                        network.sendPhz(5000, 'CheckHand/' + 'onTouchBegan' + '/movingError/' + e.toString());
                    }
                },
                onTouchMoved: function (touch, event) {
                    try {
                        if (movecard && cc.sys.isObjectValid(movecard)) {
                            var p = touch.getLocation();
                            p = movecardTmp.convertToNodeSpace(touch.getLocation());
                            p.x += movecardTmp.getPositionX() - movecardTmp.getBoundingBox().width / 2;
                            p.y += movecardTmp.getPositionY() - movecardTmp.getBoundingBox().height / 2;
                            movecardTmp.setPosition(p);
                            // if(that.isMoving == true){
                            //     return;
                            // }
                            if (p.y > CHUPAI_HEIGHT) {
                                return;
                            }
                            var isMove = false;
                            //先判断是不是移动到最左边  或者最右边  数组需要新建一列
                            var firsrCard = that.nCards0.getChildByTag(101);
                            var lastCard = that.nCards0.getChildByTag(that.cardList.length * 100 + 1);
                            if (firsrCard && that.cardList.length < 10 &&
                                (movecardTmp.getPositionX() + movecardTmp.getBoundingBox().width / 2) < firsrCard.getPositionX()) {
                                //移到最左边
                                isMove = true;
                                movetoxy = {x: 0, add: 'left', y: 0};
                                // console.log("移到最左边");
                            }
                            if (isMove == false && lastCard && that.cardList.length < 10 &&
                                (movecardTmp.getPositionX() + movecardTmp.getBoundingBox().width / 2) > lastCard.getPositionX() + lastCard.getBoundingBox().width) {
                                //移到最右边
                                isMove = true;
                                movetoxy = {x: that.cardList.length, add: 'right', y: 0};
                                // console.log("移到最右边");
                            }
                            if (isMove == false) {
                                var cardSprites = that.nCards0.getChildren();
                                for (var i = 0; i < cardSprites.length; i++) {
                                    var cardi = cardSprites[i];
                                    var moveCardMidX = movecardTmp.getPositionX() + movecardTmp.getBoundingBox().width / 2;
                                    var moveCardMidY = movecardTmp.getPositionY() + movecardTmp.getBoundingBox().height / 2;
                                    var cardiL = cardi.getPositionX() - cardi.getBoundingBox().width * 0.05;
                                    var cardiL2 = cardi.getPositionX() - cardi.getBoundingBox().width * 0.25;
                                    var cardiR = cardi.getPositionX() + cardi.getBoundingBox().width * 1.05;
                                    var cardiT = cardi.getPositionY() + cardi.getBoundingBox().height * 1;
                                    var cardiD = cardi.getPositionY();
                                    if (movecard.column == cardi.column && movecard.row == cardi.row) {
                                    } else {
                                        if (moveCardMidX >= cardiL && moveCardMidX <= cardiR) {
                                            var cardColunmTopRow = null;
                                            for (var s = 3; s >= 0; s--) {
                                                if (that.nCards0.getChildByTag(((cardi.column + 1) * 100) + s)) {
                                                    cardColunmTopRow = that.nCards0.getChildByTag(((cardi.column + 1) * 100) + s);
                                                    break;
                                                }
                                            }
                                            isMove = true;
                                            if (TouchUtil.isTouchMe(cardi, touch, event, null)) {
                                                if ((cardi.column == movexy.x && that.cardList[cardi.column].length <= MAXROW)
                                                    || (cardi.column != movexy.x && that.cardList[cardi.column].length < MAXROW)) {
                                                    movetoxy = {x: cardi.column, y: cardi.row, add: 'false'};
                                                    //强制改一下  todo spring
                                                    // console.log("spring1");
                                                    if (movetoxy.y >= that.cardList[movetoxy.x].length) movetoxy.y = that.cardList[movetoxy.x].length - 1;
                                                    if (movetoxy.y < 0) movetoxy.y = 0;
                                                    if (movetoxy.y >= MAXROW) movetoxy.y = MAXROW - 1;
                                                    break;
                                                }
                                            } else if (cardColunmTopRow && that.cardList[cardi.column].length < MAXROW &&
                                                moveCardMidY >= (cardColunmTopRow.getPositionY() + cardColunmTopRow.getBoundingBox().height)) {
                                                movetoxy = {
                                                    x: cardi.column,
                                                    y: ((cardi.column == movexy.x) ? (that.cardList[cardi.column].length - 1)
                                                        : (that.cardList[cardi.column].length)), add: 'false'
                                                };
                                                break;
                                            }
                                        }
                                        // else if (cardi.column > 0 && moveCardMidX <= cardiL && moveCardMidX >= cardiL2 && that.cardList.length < 10) {
                                        //     //之前 中间增加一
                                        //     if(that.cardList[movexy.x].length == 1 && cardi.column == (movexy.x + 1)){
                                        //     }else{
                                        //         isMove = true;
                                        //         movetoxy = {x: cardi.column, add: "mid", y: 0};
                                        //     }
                                        //     break;
                                        // }
                                    }
                                }
                            }
                            //不能移动到坎上
                            if (movetoxy && that.cardList && that.cardList[movetoxy.x] &&
                                // that.cardList[movetoxy.x].length == 3 &&
                                that.cardList[movetoxy.x][0] == that.cardList[movetoxy.x][1] &&
                                that.cardList[movetoxy.x][0] == that.cardList[movetoxy.x][2]) {
                                if (movetoxy.y < 3 && movetoxy.add == 'false') {
                                    isMove = false;
                                }
                            }
                            if (isMove == false) movetoxy = null;
                            //如果不是相同列移动， 移到能够到得列数量大于4，则不移动
                            if (movetoxy && movetoxy.x != movexy.x && that.cardList[movetoxy.x] && that.cardList[movetoxy.x].length >= MAXROW) {
                                isMove = false;
                            }
                            if (movetoxy && movetoxy.x == movexy.x && movetoxy.y == movexy.y) {
                                return;
                            }
                            // console.log(movetoxy);
                            if (movetoxy && movecard) {
                                if (((movetoxy.add == 'mid' && movetoxy.x > movexy.x) || movetoxy.add == 'right') && that.cardList[movexy.x].length == 1) {
                                    movetoxy.x = movetoxy.x - 1;
                                }
                                that.isMoving = true;
                                // console.log(movetoxy);
                                // console.log(movetoxybak);
                                if (movetoxybak && (movetoxybak.x == movetoxy.x && movetoxybak.y == movetoxy.y && movetoxybak.add == movetoxy.add)) {
                                    // console.log("移动的一样");
                                    that.isMoving = false;
                                    return;
                                }
                                for (var s = 0; s < movetocardArr.length; s++) {
                                    var card = movetocardArr[s];
                                    if (card && cc.sys.isObjectValid(card)) {
                                        card.stopAllActions();
                                        card.setPosition(movetocardPosArr[s]);
                                    }
                                }
                                movetocardArr = [];
                                movetocardPosArr = [];

                                // console.log("开始移动");
                                movetoxybak = deepCopy(movetoxy);
                                // console.log(movetoxy);
                                // console.log(movexy);
                                if (movetoxy.add != 'false') {
                                    //新加一列
                                    movecard.stopAllActions();
                                    movecard.runAction(cc.sequence(
                                        cc.delayTime(0.1),
                                        cc.callFunc(function () {
                                            that.isMoving = false;
                                        })
                                    ));
                                } else {
                                    if (movexy.x == movetoxy.x) {
                                        var card = that.nCards0.getChildByTag(100 * (movetoxy.x + 1) + movetoxy.y + 1);
                                        if (card) {
                                            movetocardArr[0] = card;
                                            movetocardPosArr[0] = card.getPosition();
                                            card.stopAllActions();
                                            card.runAction(cc.sequence(
                                                cc.moveBy(0.1, cc.p(0, (movexy.y - movetoxy.y) * (that.cardSize.h * that.cardScale - 25))),
                                                cc.callFunc(function () {
                                                    that.isMoving = false;
                                                })
                                            ));
                                        }
                                    } else {
                                        for (var n = movetoxy.y; n < 4; n++) {
                                            var nlength = movetocardArr.length;
                                            var card = that.nCards0.getChildByTag(100 * (movetoxy.x + 1) + n + 1);
                                            if (card) {
                                                movetocardArr[nlength] = card;
                                                movetocardPosArr[nlength] = card.getPosition();
                                            }
                                        }
                                        if (movetocardArr.length == 0) {
                                            movecard.stopAllActions();
                                            movecard.runAction(cc.sequence(
                                                cc.delayTime(0.2),
                                                cc.callFunc(function () {
                                                    that.isMoving = false;
                                                })
                                            ));
                                        } else {
                                            if (movetocardArr && movetocardArr.length > 0) {
                                                for (var n = 0; n < movetocardArr.length; n++) {
                                                    movetocardArr[n].stopAllActions();
                                                    movetocardArr[n].runAction(cc.sequence(
                                                        cc.moveBy(0.1, cc.p(0, (that.cardSize.h * that.cardScale - 25))),
                                                        cc.callFunc(function () {
                                                            that.isMoving = false;
                                                            // console.log("当前列加一个数据" + isMoving);
                                                        })
                                                    ));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } catch (e) {
                        network.sendPhz(5000, 'CheckHand/' + 'onTouchMoved' + '/movingError/' + e.toString());
                    }
                },
                onTouchEnded: function (touch, event) {
                    try {
                        that.showTingPaiOnDesk(tingData);
                        if (mRoom.shouxing && mRoom.sxUserId > 0) {
                            if (movecardTmp && cc.sys.isObjectValid(movecardTmp)
                                && movecardTmp.getPositionY() >= (CHUPAI_HEIGHT - movecardTmp.getContentSize().height / 2 - 20)
                                && movecardTmp.data != 21 && gameData.uid != mRoom.sxUserId) {
                                if (that.isTurnOut == true && that.nAction.isVisible() == false) {
                                    that.userShowCard(movecardTmp.data, false, movecardTmp.row, movecardTmp.column);
                                    that.setSameCardShow(movecardTmp.data, false);//选中相同颜色的
                                    movexy = null;
                                    movetoxy = null;
                                    movetoxybak = null;
                                    movecard = null;
                                    positionBak = null;
                                    return;
                                }
                            }
                        } else {
                            if (movecardTmp && cc.sys.isObjectValid(movecardTmp)
                                && movecardTmp.getPositionY() >= (CHUPAI_HEIGHT - movecardTmp.getContentSize().height / 2 - 20) && movecardTmp.data != 21) {
                                if (that.isTurnOut == true && that.nAction.isVisible() == false) {
                                    that.setSameCardShow(movecardTmp.data, false);//选中相同颜色的
                                    that.userShowCard(movecardTmp.data, false, movecardTmp.row, movecardTmp.column, movecard, positionBak);
                                    movexy = null;
                                    movetoxy = null;
                                    movetoxybak = null;
                                    if (!that._isShePao) {
                                        movecard = null;
                                        positionBak = null;
                                    }

                                    return;
                                }
                            }
                        }

                        // cc.log("-------onTouchEn :movecard : " + (movecard == null));

                        if (movecard && cc.sys.isObjectValid(movecard) && !that._isShePao) {
                            // cc.log("-------onTouchEn :movecard : " + movecard.data + " -------  :" + movetocardArr + " ------ :" + movetocardPosArr);
                            if (movecardTmp && cc.sys.isObjectValid(movecardTmp) && movecardTmp.getPositionY() >= CHUPAI_HEIGHT) {
                                if (movetocardArr && movetocardArr.length > 0) {
                                    for (var n = 0; n < movetocardArr.length; n++) {
                                        movetocardArr[n].stopAllActions();
                                        movetocardArr[n].runAction(cc.sequence(
                                            cc.moveTo(0.1, movetocardPosArr[n])
                                        ));
                                    }
                                }
                                movetocardArr = [];
                                movetocardPosArr = [];

                                movecard.stopAllActions();
                                movecardTmp.setVisible(false);
                                movecard.setPosition(movecardTmp.getPosition());
                                movecard.setOpacity(255);
                                if (movecard.getChildByName('tingmark') && cc.sys.isObjectValid(movecard.getChildByName('tingmark'))
                                    && movecard.getChildByName('tingmark').isVisible()) {
                                    movecardTmp.setTingMark(false);
                                    movecard.getChildByName('tingmark').setOpacity(255);
                                }
                                movecard.setLocalZOrder(zorderBak);
                                movecard.runAction(cc.sequence(
                                    cc.moveTo(0.1, positionBak),
                                    cc.callFunc(function (sender) {
                                        that.setSameCardShow(movecard.data, false);//选中相同颜色的
                                        movexy = null;
                                        movetoxy = null;
                                        movetoxybak = null;
                                        movecard = null;
                                        positionBak = null;
                                        that.isBeginTouch = false;
                                        that.isMoving = false;

                                        cc.sys.localStorage.setItem('Storage_handsCards', JSON.stringify(that.cardList));
                                    })
                                ));
                                that.checkHandCards();
                                return;
                            }
                            var isMoveLineDelete = true;
                            if (that.cardList[movexy.x] && that.cardList[movexy.x].length > 1) isMoveLineDelete = false;
                            that.isMoving = false;
                            var cardSprites = that.nCards0.getChildren();
                            for (var s = 0; s < movetocardArr.length; s++) {
                                var card = movetocardArr[s];
                                if (card && cc.sys.isObjectValid(card)) {
                                    card.stopAllActions();
                                    card.runAction(cc.sequence(
                                        cc.moveTo(0.1, movetocardPosArr[s])
                                    ));
                                }
                            }
                            movetocardArr = [];
                            movetocardPosArr = [];
                            //单击换牌
                            if (movetoxy == null && movetoxybak == null && that.cardList[movexy.x] && that.cardList[movexy.x].length == 2) {
                                movetoxy = {x: movexy.x, y: (movexy.y == 1) ? 0 : 1, add: 'false'};
                            }
                            if (movetoxy == null) {
                                if (movecard && movecard.data) {
                                    var cardno = movecard.data;
                                    movecardTmp.setVisible(false);
                                    movecard.setPosition(movecardTmp.getPosition());
                                    movecard.setOpacity(255);
                                    movecard.stopAllActions();

                                    if (movecard.getChildByName('tingmark') && cc.sys.isObjectValid(movecard.getChildByName('tingmark'))
                                        && movecard.getChildByName('tingmark').isVisible()) {
                                        movecardTmp.setTingMark(false);
                                        movecard.getChildByName('tingmark').setOpacity(255);
                                    }

                                    movecard.runAction(cc.sequence(
                                        cc.moveTo(0.1, cc.p(positionBak)),
                                        cc.callFunc(function (sender) {
                                            that.isBeginTouch = false;
                                        })
                                    ));
                                }
                                that.checkHandCards();
                            } else {
                                //console.log("移动到====" + movetoxy.x +"==="+movetoxy.y+"===="+movetoxy.add);
                                if (movetoxy.add == 'left') {
                                    //移动到第一列
                                    var tmp = that.cardList[movexy.x][movexy.y];
                                    var xybaktmp = deepCopy(cardsXYBak[movexy.x][movexy.y]);
                                    if (that.cardList[movexy.x].length == 1) {
                                        that.cardList[movexy.x].splice(movexy.y, 1);
                                        cardsXYBak[movexy.x].splice(movexy.y, 1);
                                        for (var i = movexy.x; i > 0; i--) {
                                            that.cardList[i] = that.cardList[i - 1];
                                            cardsXYBak[i] = cardsXYBak[i - 1];
                                        }
                                        that.cardList[0] = [];
                                        cardsXYBak[0] = [];
                                        that.cardList[0].push(tmp);
                                        cardsXYBak[0].push(xybaktmp);
                                    } else {
                                        that.cardList[movexy.x].splice(movexy.y, 1);
                                        cardsXYBak[movexy.x].splice(movexy.y, 1);
                                        for (var i = that.cardList.length - 1; i >= 0; i--) {
                                            that.cardList[i + 1] = that.cardList[i];
                                            cardsXYBak[i + 1] = cardsXYBak[i];
                                        }
                                        that.cardList[0] = [];
                                        cardsXYBak[0] = [];
                                        that.cardList[0].push(tmp);
                                        cardsXYBak[0].push(xybaktmp);
                                    }
                                    // console.log(cardsXYBak);
                                } else if (movetoxy.add == 'right') {
                                    //移动到最后一列
                                    var tmp = that.cardList[movexy.x][movexy.y];
                                    var xybaktmp = deepCopy(cardsXYBak[movexy.x][movexy.y]);
                                    if (that.cardList[movexy.x].length == 1) {
                                        that.cardList[movexy.x].splice(movexy.y, 1);
                                        cardsXYBak[movexy.x].splice(movexy.y, 1);
                                        for (var i = movexy.x; i < that.cardList.length - 1; i++) {
                                            that.cardList[i] = that.cardList[i + 1];
                                            cardsXYBak[i] = cardsXYBak[i + 1];
                                        }
                                        that.cardList[that.cardList.length - 1] = [];
                                        cardsXYBak[cardsXYBak.length - 1] = [];
                                        that.cardList[that.cardList.length - 1].push(tmp);
                                        cardsXYBak[cardsXYBak.length - 1].push(xybaktmp);
                                    } else {
                                        that.cardList[movexy.x].splice(movexy.y, 1);
                                        cardsXYBak[movexy.x].splice(movexy.y, 1);
                                        var addNum = that.cardList.length;
                                        that.cardList[addNum] = [];
                                        cardsXYBak[addNum] = [];
                                        that.cardList[addNum].push(tmp);
                                        cardsXYBak[addNum].push(xybaktmp);
                                    }
                                    // }else if(movetoxy.add == "mid") {
                                    //     //中间增加一列
                                    //     var tmp = that.cardList[movexy.x][movexy.y];
                                    //     var xybaktmp = deepCopy(cardsXYBak[movexy.x][movexy.y]);
                                    //     if (isMoveLineDelete) {
                                    //         that.cardList.splice(movexy.x, 1);
                                    //         cardsXYBak.splice(movexy.x, 1);
                                    //     } else {
                                    //         that.cardList[movexy.x].splice(movexy.y, 1);
                                    //         cardsXYBak[movexy.x].splice(movexy.y, 1);
                                    //     }
                                    //     for (var i = that.cardList.length - 1; i >= movetoxy.x; i--) {
                                    //         that.cardList[i + 1] = that.cardList[i];
                                    //         cardsXYBak[i + 1] = cardsXYBak[i];
                                    //     }
                                    //     that.cardList[movetoxy.x] = [];
                                    //     cardsXYBak[movetoxy.x] = [];
                                    //     that.cardList[movetoxy.x].push(tmp);
                                    //     cardsXYBak[movetoxy.x].push(xybaktmp);
                                } else {
                                    if (movetoxy.x == movexy.x) {
                                        //当前列交换数据
                                        if (that.cardList[movetoxy.x]) {
                                            var tmp = that.cardList[movexy.x][movexy.y];
                                            var xybaktmp = deepCopy(cardsXYBak[movexy.x][movexy.y]);
                                            that.cardList[movexy.x][movexy.y] = that.cardList[movetoxy.x][movetoxy.y];
                                            cardsXYBak[movexy.x][movexy.y] = cardsXYBak[movetoxy.x][movetoxy.y];
                                            that.cardList[movetoxy.x][movetoxy.y] = tmp;
                                            cardsXYBak[movetoxy.x][movetoxy.y] = xybaktmp;
                                        }
                                    } else {
                                        //别的列移动过来的
                                        if (that.cardList[movetoxy.x]) {
                                            var tmp = that.cardList[movexy.x][movexy.y];
                                            var xybaktmp = deepCopy(cardsXYBak[movexy.x][movexy.y]);
                                            that.cardList[movexy.x].splice(movexy.y, 1);
                                            cardsXYBak[movexy.x].splice(movexy.y, 1);
                                            //y 所有的网上移动
                                            for (var s = that.cardList[movetoxy.x].length - 1; s >= movetoxy.y; s--) {
                                                that.cardList[movetoxy.x][s + 1] = that.cardList[movetoxy.x][s];
                                                cardsXYBak[movetoxy.x][s + 1] = cardsXYBak[movetoxy.x][s];
                                            }
                                            that.cardList[movetoxy.x][movetoxy.y] = tmp;
                                            cardsXYBak[movetoxy.x][movetoxy.y] = xybaktmp;
                                        }
                                    }
                                }
                                //移除空的列
                                for (var i = 0; i < that.cardList.length; i++) {
                                    for (var j = that.cardList[i].length - 1; j >= 0; j--) {
                                        if (that.cardList[i][j] == null || that.cardList[i][j] == undefined) {
                                            that.cardList[i].splice(j, 1);
                                            cardsXYBak[i].splice(j, 1);
                                        }
                                    }
                                }
                                for (var i = 0; i < that.cardList.length; i++) {
                                    if ((that.cardList[i] == null || that.cardList[i] == undefined)
                                        || (that.cardList[i] && that.cardList[i].length == 0)) {
                                        that.cardList.splice(i, 1);
                                        cardsXYBak.splice(i, 1);
                                        break;
                                    }
                                }
                                //是否增加长度
                                var addCloumnNum = 0;
                                if (movetoxy.add == 'left' || movetoxy.add == 'right' || movetoxy.add == 'mid') {
                                    addCloumnNum = (isMoveLineDelete == false) ? 1 : 0;
                                } else {
                                    addCloumnNum = (isMoveLineDelete == false) ? 0 : -1;
                                }
                                if (addCloumnNum != 0) {
                                    firstCardPos.x = firstCardPos.x + ((addCloumnNum == -1) ? (that.cardSize.w * that.cardScale - 2) / 2 : -(that.cardSize.w * that.cardScale - 2) / 2);
                                }
                                // console.log("addCloumnNum"+addCloumnNum);
                                // console.log(that.cardList);
                                // console.log(cardsXYBak);
                                for (var i = 0; i < cardsXYBak.length; i++) {
                                    for (var j = 0; j < cardsXYBak[i].length; j++) {
                                        var tag = 0;
                                        if (cardsXYBak[i][j]) tag = cardsXYBak[i][j]['tag'];
                                        var card = that.nCards0.getChildByTag(tag);
                                        if (card && cc.sys.isObjectValid(card)) {
                                            card.stopAllActions();
                                            card.setRowColumn(j, i);
                                            card.newtag = (card.column + 1) * 100 + card.row + 1;
                                            card.runAction(cc.sequence(
                                                cc.moveTo(0.1, cc.p(firstCardPos.x + (i) * (that.cardSize.w * that.cardScale - 2),
                                                    firstCardPos.y + (j) * (that.cardSize.h * that.cardScale - 25))),
                                                cc.callFunc(function (sender) {
                                                    sender.setTag(sender.newtag);
                                                    // console.log(sender.data + "===" + sender.column + "===" + sender.row + "===" + sender.getTag());
                                                    that.isBeginTouch = false;
                                                })
                                            ));
                                        }
                                    }
                                }
                                if (movecard && cc.sys.isObjectValid(movecard)) {
                                    movecard.setRowColumn(movetoxy.y, movetoxy.x + ((addCloumnNum == -1 && movexy.x < movetoxy.x) ? -1 : 0));
                                    movecard.setTag((movetoxy.x + 1 + ((addCloumnNum == -1 && movexy.x < movetoxy.x) ? -1 : 0)) * 100 + movetoxy.y + 1);
                                    //console.log(movecard.data+"==="+movecard.column+"==="+movecard.row+"==="+movecard.getTag());
                                    var addCloumnPosx = (movetoxy.add == 'false' && addCloumnNum == -1 && movexy.x < movetoxy.x) ? -1 : 0;
                                    movecard.stopAllActions();
                                    movecardTmp.setVisible(false);
                                    movecard.setPosition(movecardTmp.getPosition());
                                    movecard.setOpacity(255);

                                    if (movecard.getChildByName('tingmark') && cc.sys.isObjectValid(movecard.getChildByName('tingmark'))
                                        && movecard.getChildByName('tingmark').isVisible()) {
                                        movecardTmp.setTingMark(false);
                                        movecard.getChildByName('tingmark').setOpacity(255);
                                    }

                                    movecard.runAction(cc.sequence(
                                        cc.moveTo(0.1, cc.p(firstCardPos.x + (movetoxy.x + addCloumnPosx) * (that.cardSize.w * that.cardScale - 2),
                                            firstCardPos.y + (movetoxy.y) * (that.cardSize.h * that.cardScale - 25))),
                                        cc.callFunc(function (sender) {
                                            that.isBeginTouch = false;
                                        })
                                    ));
                                }
                            }

                            for (var i = 0; i < cardSprites.length; i++) {
                                var card = cardSprites[i];
                                card.setLocalZOrder(3 - card.row);
                            }

                            that.setSameCardShow(movecard.data, false);//选中相同颜色的
                            movecard = null;
                            positionBak = null;
                            movecard = null;
                            movexy = null;
                            movetoxy = null;
                            movetoxybak = null;

                            cc.sys.localStorage.setItem('Storage_handsCards', JSON.stringify(that.cardList));
                        }
                    } catch (e) {
                        network.sendPhz(5000, 'CheckHand/' + 'onTouchEnded' + '/movingError/' + e.toString());
                    }
                },
                onTouchCancel: function (touch, event) {
                    //console.log("cancel!!!!!!!!");
                    try {
                        if (movecard) {
                            that.setSameCardShow(movecard.data, false);//选中相同颜色的
                            movecardTmp.setVisible(false);
                            movecard.setPosition(movecardTmp.getPosition());
                            movecard.stopAllActions();
                            movecard.runAction(cc.sequence(
                                cc.moveTo(0.1, positionBak || cc.p(0, 0)),
                                cc.delayTime(0.4),
                                cc.callFunc(function () {
                                    movexy = null;
                                    movetoxy = null;
                                    movecard = null;
                                    movetoxybak = null;
                                    that.isMoving = false;
                                    that.isBeginTouch = false;
                                })
                            ));
                        }
                    } catch (e) {
                        network.sendPhz(5000, 'CheckHand/' + 'onTouchCancel' + '/movingError/' + e.toString());
                    }
                }
            });
            return cc.eventManager.addListener(chupaiListener, touchLayer);
        },
        onBack: function (sender, type) {
            if (this.isStart == false) {
                mRoom.quitRoom(this);
            }
            else {
                // DC.wsData("Vote/quit/1/0/0");
            }
        },
        isShePao: function (card) {
            var _isShepao = false;
            for (var i = 1; i <= this.playersNum; i++) {
                if (mAction.combos[i] && mAction.combos[i].length > 0) {
                    for (var j = 0; j < mAction.combos[i].length; j++) {
                        if ((mAction.combos[i][j].typ == mCard.comboTypes.chouwei
                                || mAction.combos[i][j].typ == mCard.comboTypes.wei)
                            && parseInt(mAction.combos[i][j].cards[0]) == parseInt(card)) {
                            _isShepao = true;
                            break;
                        }
                    }
                }
            }
            return _isShepao;
        },

        onGameVote: function (data) {
            var that = this;
            if (!data.Voting) {
                return;
            }
            var byUserId = data.ByUserID;
            if (byUserId == 0) {
                return;
            }
            var leftSeconds = data.EndSecond;
            var voteResult = data.VoteResult;
            leftSeconds = (leftSeconds < 0 ? 0 : leftSeconds);

            for (var i = 0; i < gameData.players.length; i++) {
                var playerInfo = gameData.players[i];
                playerInfo.uid = playerInfo.ID;
                playerInfo.nickname = playerInfo.NickName;
                playerInfo.ip = playerInfo.IP;
                playerInfo.headimgurl = playerInfo.HeadIMGURL;
                playerInfo.sex = playerInfo.Sex;
            }

            var acceptCount = 0;
            var arr_len = -1;
            var arr = data.Users;
            if (arr) {
                for (var i = 0; i < arr.length; i++) {
                    if(arr[i])
                        if(arr[i]['VoteValue'] == 1)
                            acceptCount = acceptCount + 1;
                }
                arr_len = arr.length;
            }
            gameData.jiesanSucess = data['is_jiesan'] || acceptCount == arr_len;
            if (!this.RoomQuitWindow) {
                this.RoomQuitWindow = showWindow('RoomQuitWindow', leftSeconds, data.Users, byUserId, data);
            } else {
                this.RoomQuitWindow.setData(leftSeconds, data.Users, byUserId, data);
            }
            this.RoomQuitWindow.setVisible(true);
        },

        onVoice: function (event) {
            //语音
            var data = event;
            var respJson = JSON.parse(data.Msg);
            var uid = respJson['from'] || respJson['uid'];
            var type = respJson['type'];
            var voice = respJson['voice'];
            var content = respJson['content'];
            //row
            var row = mRoom.getUserPosIndex(uid);
            // this.showChat(row, type, content, voice, uid);
        },
        //跑马灯
        onMaDeng: function (event) {
            var that = this;
            var data = event;

            var interval = null;
            if (data && (data.Content == '' || data.Content == null)) {
                return;
            }
            var func = function () {
                if (!that || !cc.sys.isObjectValid(that)) {
                    if (interval) {
                        clearInterval(interval);
                        interval = null;
                    }
                    return;
                }
                var content = data.Content;
                that.pmdContent = content;
                gameData.pmdContent = content;
                var speaker = $('speaker');
                speaker.setVisible(true);
                speaker.setLocalZOrder(100);
                var speakerPanel = $('speaker.speakerpanel');
                speaker.runAction(cc.fadeIn(0.2));
                var text = new ccui.Text();
                text.setFontSize(26);
                text.setColor(cc.color(254, 245, 92));
                text.setAnchorPoint(cc.p(0, 0));
                text.enableOutline(cc.color(0, 0, 0), 1);
                speakerPanel.removeAllChildren();
                speakerPanel.addChild(text);
                text.setString(content);
                text.setPositionX(speakerPanel.getContentSize().width);
                text.setPositionY(5);
                text.runAction(cc.sequence(
                    cc.delayTime(0.2),
                    cc.moveTo((content.length * 0.3 <= 10) ? 10 : content.length * 0.3, -text.getVirtualRendererSize().width, 5),
                    cc.delayTime(0.3),
                    cc.callFunc(function () {
                        speaker.runAction(cc.fadeOut(0.2));
                    })
                ));
            };
            func();
            var t = (that.pmdContent.length * 0.3 <= 30) ? 30 : (that.pmdContent.length * 0.3 + 5);
            interval = setInterval(func, t * 1000);
        },
        playUrlVoice: function (row, type, content, voice) {
            var url = decodeURIComponent(content);
            var arr = null;
            if (url.indexOf('.aac') >= 0) {
                arr = url.split(/\.aac/)[0].split(/-/);
            } else if (url.indexOf('.spx') >= 0) {
                arr = url.split(/\.spx/)[0].split(/-/);
                // playVoiceByUrl(url);
            }
            var duration = arr[arr.length - 1] / 1000;
            window.soundQueue = window.soundQueue || [];
            window.soundQueue.push({url: url, duration: duration, row: row});
            if (window.soundQueue.length > 1) {
            } else {
                this.playVoiceQueue();
            }
        },
        playVoiceQueue: function () {
            var that = this;
            var queue = window.soundQueue[0];
            if (queue && queue.url && queue.duration && _.isNumber(queue.row)) {
                jsb.AudioEngine.pauseAll();
                if (queue.url.indexOf('.aac') >= 0) {
                    VoiceUtils.play(queue.url);
                } else if (queue.url.indexOf('.spx') >= 0) {
                    OldVoiceUtils.playVoiceByUrl(queue.url);
                }
                // var scale9sprite = this.initQP(queue.row);
                // var index = -1;
                // if (queue.row == 0) index = 2;
                // if (queue.row == 1) index = 1;
                // if (queue.row == 2) index = 3;
                // if (queue.row == 3) index = 0;
                // scale9sprite.setContentSize(this.ltqpVoiceSize[queue.row]);
                // var innerNodes = this.initSpeaker(queue.row, scale9sprite);
                // this.qpAction(innerNodes, scale9sprite, queue.duration);
                // setTimeout(function () {
                //     window.soundQueue.shift();
                //     that.playVoiceQueue();
                // }, queue.duration * 1000);
            } else {
                jsb.AudioEngine.resumeAll();
            }
        },
        initQP: function (row) {
            var that = this;
            var head = $('node.info' + row + '.head' + row, this.playersInfo);
            // if(!head) return null;
            var scale9sprite = head.getChildByName('qp9');
            var qprow = head.getChildByName('qp' + row);
            var index = -1;
            var fourPChangeRow = -1;
            if (mRoom.wanfatype == mRoom.LEIYANG) {
                if (row == 0) index = 2;
                if (row == 1) index = 1;
                if (row == 2) index = 3;
            } else if (mRoom.wanfatype == mRoom.HENGYANG) {
                if (row == 0) index = 2;
                if (row == 1) index = 1;
                if (row == 2) index = 3;
                if (row == 3) index = 3;
            }
            if (!scale9sprite) {
                if (this.playersNum == 3) {
                    scale9sprite = new cc.Scale9Sprite(res['ltqp' + index], that.ltqpRect[index], that.ltqpCapInsets[index]);
                    scale9sprite.setAnchorPoint(row == 1 ? cc.p(1, 0) : cc.p(0, 0));
                } else if (mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.QIYANG) {
                    if (row == 0 || row == 3) {
                        fourPChangeRow = index;
                    } else {
                        fourPChangeRow = 1;
                    }
                    scale9sprite = new cc.Scale9Sprite(res['ltqp' + fourPChangeRow], that.ltqpRect[fourPChangeRow], that.ltqpCapInsets[fourPChangeRow]);
                    scale9sprite.setAnchorPoint((row == 1 || row == 2) ? cc.p(1, 0) : cc.p(0, 0));
                } else {
                    if (row == 1 || row == 2) {
                        fourPChangeRow = 1;
                    } else if (row == 3) {
                        fourPChangeRow = 0;
                    }
                    scale9sprite = new cc.Scale9Sprite(res['ltqp' + fourPChangeRow], that.ltqpRect[fourPChangeRow], that.ltqpCapInsets[fourPChangeRow]);
                    scale9sprite.setAnchorPoint((row == 1 || row == 2) ? cc.p(1, 0) : cc.p(0, 0));
                }
                scale9sprite.setName('qp9');
                //scale9sprite.setPosition(cc.p(qprow.getPosition().x + that.ltqpPos[row].x, qprow.getPosition().y + that.ltqpPos[row].y));
                scale9sprite.setPosition(cc.p(qprow.getPosition().x, qprow.getPosition().y));
                head.addChild(scale9sprite);
            }

            for (var i = (cc.sys.isNative ? 0 : 1); i < scale9sprite.getChildren().length; i++)
                scale9sprite.getChildren()[i].setVisible(false);
            return scale9sprite;
        },
        initSpeaker: function (row, scale9sprite) {
            var map = {};
            var innerNodes = [];
            scale9sprite.setContentSize(this.ltqpEmojiSize[row]);
            for (var i = 1; i <= 3; i++) {
                var sp = $('speaker' + i, scale9sprite);
                if (!sp) {
                    sp = new cc.Sprite('res/table/speaker' + i + '.png');
                    sp.setName('speaker' + i);
                    sp.setPosition(this.ltqpVoicePos[row]);
                    scale9sprite.addChild(sp);
                }
                map[i] = sp;
                map[i].setVisible(true);
                innerNodes.push(map[i]);
            }
            map[2].runAction(cc.sequence(cc.fadeOut(0), cc.delayTime(0.25), cc.fadeIn(0.25)).repeatForever());
            map[3].runAction(cc.sequence(cc.fadeOut(0), cc.delayTime(0.50), cc.fadeIn(0.50)).repeatForever());
            return innerNodes;
        },
        qpAction: function (innerNodes, scale9sprite, duration) {
            if (scale9sprite == undefined || !cc.sys.isObjectValid(scale9sprite)) {
                return;
            }
            scale9sprite.stopAllActions();
            scale9sprite.setVisible(true);
            scale9sprite.setOpacity(255);
            scale9sprite.setScale(1.6, 1.6);
            scale9sprite.runAction(cc.sequence(cc.delayTime(duration), cc.fadeOut(0.5), cc.callFunc(function () {
                for (var i = 0; i < innerNodes.length; i++)
                    innerNodes[i].setVisible(false);
            })));
        },
        // showChat: function (row, type, content, voice, uid) {
        //     if (uid == gameData.uid && (type == 'user_back' || type == 'user_leave')) {
        //         return;
        //     }
        //     //回放不播放语音聊天
        //     if (mRoom.isReplay == true) {
        //         return;
        //     }
        //
        //     if (type == 'voice') {
        //         var url = decodeURIComponent(content);
        //         if (url && url.split(/\.spx/).length > 2) {
        //             return;
        //         }
        //     }
        //
        //     if (type == 'voice') {
        //         this.playUrlVoice(row, type, content, voice);
        //         return;
        //     }
        //
        //     //biaoqingdonghua1
        //     if (type == 'biaoqingdonghua') {
        //         if (this._useNewProp) {
        //             var data = JSON.parse(content);
        //             network.selfRecv({'code': 4990, 'data': data});
        //             return;
        //         }
        //         // cc.eventManager.dispatchCustomEvent(P.GS_BIAOQING,  JSON.parse(content));
        //         var data = JSON.parse(content);
        //         PlayerInfoLayer.addEffectEmojiQueue(data.from_uid, data.target_uid, data.emoji_idx, data.emoji_times);
        //         return;
        //     }
        //     //row转换
        //     var that = this;
        //     var head = $('node.info' + row + '.head' + row, this.playersInfo);
        //     var scale9sprite = head.getChildByName('qp9');
        //     var qprow = head.getChildByName('qp' + row);
        //     var index = -1;
        //     var fourPChangeRow = -1;
        //     if (mRoom.wanfatype == mRoom.LEIYANG || mRoom.wanfatype == mRoom.SHIHUKA) {
        //         if (row == 0) index = 2;
        //         if (row == 1) index = 1;
        //         if (row == 2) index = 3;
        //     } else if (mRoom.wanfatype == mRoom.HENGYANG) {
        //         if (row == 0) index = 2;
        //         if (row == 1) index = 1;
        //         if (row == 2) index = 3;
        //         if (row == 3) index = 3;
        //     }
        //
        //     if (!scale9sprite) {
        //         if (this.playersNum == 3) {
        //             scale9sprite = new cc.Scale9Sprite(res['ltqp' + index], that.ltqpRect[index], that.ltqpCapInsets[index]);
        //             scale9sprite.setAnchorPoint(row == 1 ? cc.p(1, 0) : cc.p(0, 0));
        //         } else if (mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.QIYANG) {
        //
        //             if (row == 0 || row == 3) {
        //                 fourPChangeRow = index;
        //             } else {
        //                 fourPChangeRow = 1;
        //             }
        //             scale9sprite = new cc.Scale9Sprite(res['ltqp' + fourPChangeRow], that.ltqpRect[fourPChangeRow], that.ltqpCapInsets[fourPChangeRow]);
        //             scale9sprite.setAnchorPoint((row == 1 || row == 2) ? cc.p(1, 0) : cc.p(0, 0));
        //         }
        //         else {
        //             if (row == 0 || row == 2) {
        //                 fourPChangeRow = 3;
        //             } else {
        //                 fourPChangeRow = 1;
        //             }
        //             scale9sprite = new cc.Scale9Sprite(res['ltqp' + fourPChangeRow], that.ltqpRect[fourPChangeRow], that.ltqpCapInsets[fourPChangeRow]);
        //             scale9sprite.setAnchorPoint((row == 1 || row == 2) ? cc.p(1, 0) : cc.p(0, 0));
        //         }
        //         scale9sprite.setName('qp9');
        //         scale9sprite.setPosition(cc.p(qprow.getPosition().x, qprow.getPosition().y + that.ltqpPos[row].y));
        //         head.addChild(scale9sprite);
        //     } else if (mRoom.wanfatype == mRoom.HENGYANG) {
        //         if (row == 0 || row == 3) {
        //             index = index;
        //         } else {
        //             index = 1;
        //         }
        //     }
        //
        //     for (var i = (cc.sys.isNative ? 0 : 1); i < scale9sprite.getChildren().length; i++)
        //         scale9sprite.getChildren()[i].setVisible(false);
        //
        //     var duration = row == 0 ? 2 : 4;
        //     var innerNodes = [];
        //     var playerNum = gameData.playerNum;
        //     if (type == 'emoji') {
        //         // scale9sprite.setContentSize(this.ltqpEmojiSize[row]);
        //         // var sprite = $("emoji", head);
        //         // if (!sprite) {
        //         //     sprite = new cc.Sprite();
        //         //     sprite.setName('emoji');
        //         //     sprite.setPosition(cc.p(qprow.getPosition().x, qprow.getPosition().y));
        //         //     head.addChild(sprite);
        //         // }
        //         // sprite.setScale(1.4);
        //         // scale9sprite.setVisible(false);
        //         // // this.setSpriteFrameByName(sprite, content, 'emoji');
        //         // sprite.setTexture('res/expression/' + content + '.png');
        //         // sprite.setVisible(true);
        //         // innerNodes.push(sprite);
        //
        //         // scale9sprite.setOpacity(0);
        //         //scale9sprite.setContentSize(this.ltqpEmojiSize[row]);
        //
        //
        //         //表情动画
        //         if (!this._useNewProp) {
        //             var id = content.substring(10, 11);
        //             var ccsScene = ccs.load(res['expression' + id]);
        //             var express = ccsScene.node;
        //             // express.setPosition(cc.p(qprow.getPosition().x - 100, qprow.getPosition().y - 150));
        //             express.setPosition(this.ltqpEmojiPos[row]);
        //             express.setName('express');
        //             $('node.info' + row, this.playersInfo).addChild(express);
        //             express.runAction(ccsScene.action);
        //             ccsScene.action.play('action', true);
        //             this.scheduleOnce(function () {
        //                 // scale9sprite.setOpacity(0);
        //                 express.removeFromParent();
        //             }, 2);
        //         } else {
        //             //新版表情动画3
        //             duration = 2.2;
        //             // scale9sprite.setOpacity(0);
        //             scale9sprite.setContentSize(this.ltqpEmojiSize[row]);
        //             var rowinfo = $('node.info' + row, this.playersInfo);
        //             var sprite = $('emoji', rowinfo);
        //             if (sprite) {
        //                 sprite.removeFromParent();
        //                 sprite = null;
        //             }
        //             if (!sprite) {
        //                 sprite = new cc.Sprite();
        //                 sprite.setName('emoji');
        //                 sprite.setScale(1);
        //                 sprite.setPosition(this.ltqpEmojiPos[playerNum][row]);
        //                 $('node.info' + row, this.playersInfo).addChild(sprite);
        //             }
        //
        //             if (content.indexOf('sp_') == 0) {
        //                 duration = 5;
        //                 var name = content.split('_')[1];
        //                 if (name == 'laotou' || name == 'tuxue') {
        //                     var psX = sprite.convertToWorldSpace(sprite.getPosition());
        //                     // cc.log("psXpsXpsX===="+psX.x)
        //                     if (psX.x > cc.winSize.width / 2) {
        //                         sprite.setScaleX(-1);
        //                     }
        //                 }
        //                 if (name == 'tuxue' || name == 'chuizhuozi') {
        //                     var time = 0;
        //                     if (name == 'chuizhuozi') {
        //                         time = 2000;
        //                     }
        //                     setTimeout(function () {
        //                         playEffect('vEffect_emoji_' + name);
        //                     }, time);
        //
        //                     var emoji = playSpAnimation(name, name + 1, false, null, function () {
        //                         setTimeout(function () {
        //                             emoji.removeFromParent(true);
        //                         }, 10);
        //
        //                     });
        //                 } else {
        //                     var emoji = playSpAnimation(name, name + 1, false, null, function () {
        //                         setTimeout(function () {
        //                             emoji.removeFromParent(true);
        //                         }, 10);
        //                         playEffect('vEffect_emoji_' + name);
        //                         var emoji2 = playSpAnimation(name, name + 2, false, null, function () {
        //                             setTimeout(function () {
        //                                 emoji2.removeFromParent(true);
        //                             }, 10);
        //                         });
        //                         sprite.addChild(emoji2);
        //                     });
        //                 }
        //
        //                 sprite.addChild(emoji);
        //             } else {
        //                 var _idx = content.indexOf('01.png');
        //                 if (_idx != undefined && _idx >= 0) {
        //                     content = content.substring(0, _idx);
        //                 }
        //                 var resPath = res[content];
        //                 if (resPath) {
        //                     playAnimScene(sprite, resPath, 0, 0, true);
        //                 } else {
        //                     this.setSpriteFrameByName(sprite, content, 'emoji');
        //                 }
        //             }
        //             sprite.setVisible(true);
        //             sprite.setOpacity(255);
        //             innerNodes.push(sprite);
        //         }
        //     }
        //     else if (type == 'text' || type == 'user_leave' || type == 'user_back') {
        //         var text = $('text', scale9sprite);
        //         if (!text) {
        //             text = new ccui.Text();
        //             text.setName('text');
        //             text.setFontSize(20);
        //             text.setTextColor(cc.color(255, 255, 255));
        //             text.setAnchorPoint(0, 0);
        //             text.enableOutline(cc.color(67, 99, 101), 2);
        //             scale9sprite.setOpacity(255);
        //             scale9sprite.addChild(text);
        //         }
        //         text.setString(content);
        //         // if(!this || !this.ltqpRect || !this.ltqpRect[index]){
        //         //     return;
        //         // }
        //         var size = cc.size(text.getVirtualRendererSize().width + this.ltqpRect[index].width / 2, this.ltqpRect[index].height);
        //         text.setPosition(
        //             (size.width - text.getVirtualRendererSize().width) / 2 + this.ltqpTextDelta[row].x,
        //             (size.height - text.getVirtualRendererSize().height) / 2 + this.ltqpTextDelta[row].y
        //         );
        //         scale9sprite.setContentSize(size);
        //         text.setVisible(true);
        //         innerNodes.push(text);
        //         if (type == 'user_leave') {
        //             //用户切home
        //             this.setDisconnect(uid, true);
        //         } else if (type == 'user_back') {
        //             this.setDisconnect(uid, false);
        //         }
        //     } else if (type == 'voice') {
        //         // var url = decodeURIComponent(content);
        //         // // playVoiceByUrl(url);
        //         // VoiceUtils.play(url);
        //         //
        //         // scale9sprite.setContentSize(this.ltqpEmojiSize[index]);
        //         // var map = {};
        //         // for (var i = 1; i <= 3; i++) {
        //         //     var sp = scale9sprite.getChildByName('speaker' + i);
        //         //     if (!sp) {
        //         //         sp = new cc.Sprite('res/table/speaker' + i + '.png');
        //         //         sp.setName('speaker' + i);
        //         //         sp.setPosition(that.ltqpVoicePos[index]);
        //         //         scale9sprite.addChild(sp);
        //         //     }
        //         //     map[i] = sp;
        //         //     map[i].setVisible(true);
        //         //     innerNodes.push(map[i]);
        //         // }
        //         // map[2].runAction(cc.sequence(cc.fadeOut(0), cc.delayTime(0.25), cc.fadeIn(0.25)).repeatForever());
        //         // map[3].runAction(cc.sequence(cc.fadeOut(0), cc.delayTime(0.50), cc.fadeIn(0.50)).repeatForever());
        //     } else if (type == 'location') {
        //         //位置共享
        //         var players = gameData.players;
        //         for (var i = 0; i < players.length; i++) {
        //             if (players[i].ID == uid) {
        //                 players[i].isOpenLocation = content;
        //                 break;
        //             }
        //         }
        //     }
        //
        //     scale9sprite.stopAllActions();
        //     scale9sprite.setVisible((type == 'emoji' || type == 'location') ? false : true);
        //     scale9sprite.setOpacity(255);
        //     scale9sprite.setScale(1.6, 1.6);
        //     scale9sprite.runAction(cc.sequence(cc.delayTime(duration), cc.fadeOut(row == 0 ? 0.2 : 0.5), cc.callFunc(function () {
        //         for (var i = 0; i < innerNodes.length; i++)
        //             innerNodes[i].setVisible(false);
        //     })));
        //
        //     if (type != 'voice') {
        //         for (var i = 0; i < innerNodes.length; i++) {
        //             var innerNode = innerNodes[i];
        //             innerNode.stopAllActions();
        //             innerNode.setVisible(true);
        //             innerNode.setOpacity(255);
        //             //innerNode.setScale(1.5, 1.5);
        //             innerNode.runAction(cc.sequence(cc.delayTime(duration), cc.fadeOut(0.5)));
        //         }
        //     }
        //     if (voice && !window.inReview)
        //         playEffect(voice);
        // },

        setSpriteFrameByName: function (_pai, paiName) {
            if (!this._loadPaiPlist) {
                this._loadPaiPlist = true;
                cc.spriteFrameCache.addSpriteFrames(huzi.res.card_common_plist);
                cc.spriteFrameCache.addSpriteFrames(huzi.res.card_plist);
                cc.spriteFrameCache.addSpriteFrames(huzi.res.hand_plist);
                cc.spriteFrameCache.addSpriteFrames(huzi.res.finger_plist);
            }
            setSpriteFrameByName(_pai, paiName, huzi.res.card_plist);
        },

        onReady: function (sender, type) {
            //情理上局留下的别人的手牌
            for (var i = 1; i < this.playersNum; i++) {
                this['nCards' + i].removeAllChildren();
            }
            //如果二人玩有发第三人牌时，需清理
            if (this.isErrenwanSipai()) {
                if (this['nCards2'])
                    this['nCards2'].removeAllChildren();
            }

            mRoom['CardList'] = null;

            this.imgAct.stopAllActions();
            this.imgAct.removeAllChildren();
            this.imgAct.setOpacity(0);
            this.huAni.setOpacity(0);

            tingData = [];
            this.clearTingPai();
            this.isReady = true;
            this.panelResult.setVisible(false);
            this.btReady.setVisible(false);
            this.btJiesuan.setVisible(false);
            this.rect_bg.setVisible(false);
            if (mRoom.wanfatype == mRoom.FANGPAOFA ||
                mRoom.wanfatype == mRoom.SHAOYANGBOPI ||
                mRoom.wanfatype == mRoom.XIANGXIANG) {
                network.sendPhz(5000, 'Ready');
                this.clearRoom();
            } else {
                if (mRoom.curRound >= mRoom.rounds) {
                } else {
                    network.sendPhz(5000, 'Ready');
                    this.clearRoom();
                }
            }
            var players = gameData.players;
            for (var i = 0; i < players.length; i++) {
                if (mRoom.wanfatype == mRoom.LEIYANG) {
                    this.setJushou(players[i].ID, 0, 0, false);//举手
                }
                this.setBaojing(players[i].ID, 0);//报警
            }

        },
        onJiesuan: function (sender, type) {
            this.showGameResult(true);
        },
        showReadyJiesuan: function (flag) {
            this.btReady.setVisible(flag);
            this.btJiesuan.setVisible(flag);
            this.rect_bg.setVisible(false);
        },
        onTimer: function (cdbarAniFalse) {
            if (mRoom.isPause == true) {
                return;
            }
            var cd = this.cd;//this.turnPos
            // var rotate = [0, -135, 135];
            // var toupos = [cc.p(45, -20), cc.p(90, 100), cc.p(0, 100),];
            // $('cd.arrow_tou').setRotation(rotate[this.turnPos]);
            // $('cd.arrow_tou').setPosition(toupos[this.turnPos]);
            var rotate = [0, -135, 135];
            var toupos = [cc.p(45, -20), cc.p(90, 100), cc.p(0, 100),];
            if (this.playersNum == 4) {
                if (mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.HENGDONG || mRoom.wanfatype == mRoom.MAOHUZI) {
                    rotate = [0, -45, -135, 135];
                    toupos = [cc.p(45, -20), cc.p(100, -20), cc.p(100, 100), cc.p(-20, 100)];
                }
                $('cd.arrow_tou').setRotation(rotate[this.turnPos]);
                $('cd.arrow_tou').setPosition(toupos[this.turnPos]);
            } else {
                $('cd.arrow_tou').setRotation(rotate[this.turnPos]);
                $('cd.arrow_tou').setPosition(toupos[this.turnPos]);
            }
            cd.setVisible(true);
            //cd 中显示光圈
            if (mRoom.isReplay != true && this.isStart == true) {
                for (var i = 0; i < this.playersNum; i++) {
                    var head = $('node.info' + i + '.head' + i, this.playersInfo);
                    var guangquan = head.getChildByName('guangquan');
                    if (!guangquan) {
                        var ccsScene = ccs.load(res.PhzHead_json);
                        // var ccsScene = ccs.load("res/Quan.json", "res/");
                        guangquan = ccsScene.node;
                        // guangquan.setScale(0.8);
                        guangquan.setName('guangquan');
                        guangquan.setPosition(cc.p(head.getContentSize().width / 2, head.getContentSize().height / 2));
                        head.addChild(guangquan);
                        guangquan.runAction(ccsScene.action);
                        ccsScene.action.play('action', true);
                    }
                    guangquan.setVisible((i == this.turnPos) ? true : false);
                }
            }
            //有手牌   才显示倒计时
            var hasCard = function () {
                if (mRoom['CardList'] && mRoom['CardList'].length > 0) {
                    return true;
                }
                return false;
            };
            if (this.secondsLeft > 0 && hasCard() == true) {
                this.secondsLeft -= 1;
                this.cdtext.setString(this.secondsLeft);
                cd.setVisible(true);

                var bili = this.secondsLeft / 25 * 100;
                if (cdbarAniFalse != false) {
                    this.cdbar.runAction(
                        cc.progressTo(1, bili)
                    );
                }
                var cdbarsprite = this.cdbar.getSprite();
                cdbarsprite.setTexture((this.secondsLeft < 13) ? res.redquan_png : res.greenquan_png);
                if (this.secondsLeft >= 0 && this.secondsLeft <= 5) {
                    playEffect('vCountDown');
                }
                //倒计时震动
                if (this.secondsLeft == 0) {
                    if (this.isTurnOut == true || this.isTurnIn == true)
                        DeviceUtil.vibrate();
                }
                if (this.secondsLeft == 15) {
                    if (this.isTurnOut)
                        this.fingerAni(true);
                }
            } else {
                if (this.isStart == true && hasCard() == true) {
                    cd.setVisible(true);
                    this.cdtext.setString('0');
                }
            }
        },
        // 电量状态
        onBattery: function () {
            if (!this || !cc.sys.isObjectValid(this))
                return;
            var battery = $('battery');
            var level = DeviceUtil.getBatteryLevel();
            if (cc.sys.isObjectValid(battery)) {
                if (level > 75) {
                    battery.setTexture(BatteryTextures['battery5']);
                } else if (level > 50) {
                    battery.setTexture(BatteryTextures['battery4']);
                } else if (level > 25) {
                    battery.setTexture(BatteryTextures['battery3']);
                } else if (level > 10) {
                    battery.setTexture(BatteryTextures['battery2']);
                } else {
                    battery.setTexture(BatteryTextures['battery1']);
                }
            }
        },
        // 刷新时间
        refreshTime: function () {
            if (mRoom.isReplay && mRoom.replayTime) {
                var timeArr = mRoom.replayTime.split(' ');
                var time = timeArr[1].split(':');
                if (time && time.length == 3) this.lbTime.setString(time[0] + ':' + time[1]);
            } else {
                var date = new Date();
                var seconds = date.getSeconds();
                var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
                var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
                if (cc.sys.isObjectValid(this.lbTime)) {
                    var maohao = ' ';
                    if ((seconds % 2 == 1)) {
                        maohao = ':';
                    }
                    this.lbTime.setString(hours + maohao + minutes);
                }
            }
        },

        // 显示吃、碰、过、胡 按钮
        showActions: function (actList) {
            this.nAction.setVisible(true);
            var index = 0;
            var count = actList.length;
            this.bigAction = GUO;
            for (var i = 0; i < this.listActBtn.length; i++) {
                var bt = this.listActBtn[i];
                var btAct = mAction.getBTAct(i, actList);
                var callFunc = cc.callFunc(function (target, data) {
                    target.setPositionX((data.index - 0.5 * (data.count - 1)) * 160);
                }, bt, {index: index, count: count});
                if (btAct > 0) {
                    bt.setVisible(true);
                    bt.setScale(0);
                    bt.runAction(
                        cc.sequence(
                            callFunc,
                            cc.spawn(
                                cc.sequence(
                                    cc.scaleTo(0.1, 1, 1)
                                ),
                                cc.fadeIn(0.3)
                            )
                        )
                    );

                    switch (i) {
                        case 1:
                            this.bigAction = CHI;
                            break;
                        case 2:
                            this.bigAction = PENG;
                            break;
                        case 0:
                            this.bigAction = HU;
                            break;
                    }

                    if (btAct == GUO) {
                        bt.setTag(4);
                    } else if (btAct == WEI) {
                        bt.setTag(5);
                    } else if (btAct == PAO) {
                        bt.setTag(6);
                    }
                    index++;
                } else {
                    bt.setVisible(false);
                }
            }
        },
        //录像回放  小手点击
        showReplayAction: function (action) {
            if (!this.playersInfo || !cc.sys.isObjectValid(this.playersInfo)) return;
            var actionData = action.split('/');
            var userId = actionData[0];
            var mainAction = actionData[1];
            var subAction = actionData[2];
            var replay_act = null;
            if (subAction == 'chi' || subAction == 'peng' || subAction == 'hu' || subAction == 'guo') {
                var pos = this.getUserPosIndex(userId);
                replay_act = $('node.replay_act' + pos, this.playersInfo);
                if (!!replay_act) {
                    replay_act.setVisible(true);
                    var bt = $(subAction, replay_act);
                    this.playHand(bt);
                }
            }
        },
        playHand: function (bt) {
            // cc.spriteFrameCache.addSpriteFrames('res/paohuzi/hand.plist');
            cc.spriteFrameCache.addSpriteFrames(res.hand_plist);
            var animFrames = [cc.spriteFrameCache.getSpriteFrame('hand0.png'), cc.spriteFrameCache.getSpriteFrame('hand1.png')];
            var animation = new cc.Animation(animFrames, 0.2);
            var action = cc.animate(animation);
            var sprite = new cc.Sprite(animFrames[0]);
            sprite.x = 40;
            sprite.y = 20;
            bt.addChild(sprite);
            sprite.runAction(action);
        },
        hideReplayAction: function () {
            for (var i = 0; i < this.playersNum; i++) {
                if (cc.sys.isObjectValid(this.playersInfo)) {
                    var replay_act = $('node.replay_act' + i, this.playersInfo);
                    $('node.replay_act' + i + '.chi', this.playersInfo).removeAllChildren();
                    $('node.replay_act' + i + '.peng', this.playersInfo).removeAllChildren();
                    $('node.replay_act' + i + '.hu', this.playersInfo).removeAllChildren();
                    $('node.replay_act' + i + '.guo', this.playersInfo).removeAllChildren();
                    replay_act.setVisible(false);
                }
            }
        },
        onActionBtn: function (tag, target) {
            var that = this;

            if (that.isBeginTouch) {
                if (movecard && positionBak && (this.isBeginTouch)) {
                    if (zorderBak) movecard.setLocalZOrder(zorderBak);
                    movecardTmp.setVisible(false);
                    movecard.stopAllActions();
                    movecard.setPosition(movecardTmp.getPosition());
                    movecard.setOpacity(255);
                    movecard.runAction(cc.sequence(
                        cc.moveTo(0.1, positionBak),
                        cc.callFunc(function (sender) {
                            movexy = null;
                            movetoxy = null;
                            movetoxybak = null;
                            movecard = null;
                            positionBak = null;
                            that.isMoving = false;
                            that.isBeginTouch = false;
                            sender = null;
                            // cc.log("----------onActionBtn  callFunc ");
                        })
                    ));
                }
                return;
            }

            if (tag == 2) {
                var hubtn = $('bt1', this.nAction);
                if (hubtn.isVisible() == true) {
                    showMessageBox('当前可以胡牌，请问是否选择吃?', function () {
                        that.showChiSelect();
                    });
                } else {
                    that.showChiSelect();
                }
            } else if (tag == 3) {
                var hubtn = $('bt1', this.nAction);
                if (hubtn.isVisible() == true) {
                    showMessageBox('当前可以胡牌，请问是否选择碰?', function () {
                        that.userAct(PENG, that.showNo, target);
                    });
                } else {
                    that.userAct(PENG, that.showNo, target);
                }
            } else if (tag == 1) {
                that.userAct(HU, that.showNo, target);
            } else if (tag == 4) {
                //过得时候判断一下  有没有 胡的选项,有的话,提示
                var hubtn = $('bt1', this.nAction);
                if (hubtn.isVisible() == true) {
                    showMessageBox('当前可以胡牌，请问是否选择过?', function () {
                        that.userAct(GUO, that.showNo, target);
                    });
                } else {
                    that.userAct(GUO, that.showNo, target);
                }
            }
            Filter.remove(target);
        },

        showChiSelect: function () {
            var chiList = null;
            chiList = this.chiArray;

            this.nChiList.removeAllChildren();
            if (chiList == null) return;

            var chibilayer = new ChiBiLayer();
            this.nChiList.addChild(chibilayer, 2);
            chibilayer.setData(chiList, this.showNo, this);
        },

        onTurnIn: function (event) {                   //进牌
            var data = event;
            this.goTurnIn(data.Card, data.Flag, data.Remark, data.Seq, data.ChiList, data.Cards);
        },
        getChiListByServer: function (chiListServer) {
            if (chiListServer == null || chiListServer == undefined) return null;
            var chiArray = [];
            for (var i = 0; i < chiListServer.Nodes.length; i++) {
                var chionei = [];
                if (chiListServer.Nodes[i].Cards.length > 0) {
                    for (var j = 0; j < chiListServer.Nodes[i].Cards.length; j++) {
                        chionei.push(chiListServer.Nodes[i].Cards[j]);
                    }
                }
                if (chiListServer.Nodes[i].Nodes.length > 0) {
                    var chionex = [];
                    for (var j = 0; j < chiListServer.Nodes[i].Nodes.length; j++) {
                        var chionej = [];
                        for (var l = 0; l < chiListServer.Nodes[i].Nodes[j].Cards.length; l++) {
                            chionej.push(chiListServer.Nodes[i].Nodes[j].Cards[l]);
                        }
                        //
                        if (chiListServer.Nodes[i].Nodes[j].Nodes.length > 0) {
                            var chioney = [];
                            for (var k = 0; k < chiListServer.Nodes[i].Nodes[j].Nodes.length; k++) {
                                var chionek = chiListServer.Nodes[i].Nodes[j].Nodes[k].Cards;
                                chioney.push(chionek);
                            }
                            chionej.push(chioney);
                        }
                        chionex.push(chionej);
                    }
                    chionei.push(chionex);
                }
                chiArray.push(chionei);
            }
            return chiArray;
        },

        goTurnIn: function (card, flag, remark, seq, ChiList, cards) {
            if (cards && cards.length >= 0) {
                this.checkIsShaoPai(gameData.uid, cards, 'goTurnIn');
            }
            this.chiArray = null;
            this.nChiList.removeAllChildren();
            this.isTurnOut = false;
            this.isTurnIn = true;
            mRoom.inSeq = seq;

            // cc.log("turn in id +++++", gameData.uid, remark, flag);

            // this.turnPos = 0;  this.getUserPosIndex(userId);
            this.secondsLeft = 25;

            this.turnInData = {};
            this.turnInData.Card = card;
            this.turnInData.Flag = flag;

            //改到后端计算  debug spring
            this.chiArray = this.getChiListByServer(ChiList);
            //只有一个过
            if (flag == GUO) {
                return;
            }
            var chi = ((flag & CHI) > 0) ? true : false;
            var peng = ((flag & PENG) > 0) ? true : false;
            var hu = ((flag & HU) > 0) ? true : false;
            var guo = ((flag & GUO) > 0) ? true : false;
            var pao = ((flag & PAO) > 0) ? true : false;
            var ti = ((flag & TI) > 0) ? true : false;
            var wei = ((flag & WEI) > 0) ? true : false;
            var chouwei = ((flag & CHOUWEI) > 0) ? true : false;
            var tianhu = ((flag & TIANHU) > 0) ? true : false;//TIANHU
            var actList = [];
            if (tianhu == true) {
                if (mRoom.wanfatype == mRoom.FANGPAOFA ||
                    mRoom.wanfatype == mRoom.SHAOYANGBOPI ||
                    mRoom.wanfatype == mRoom.XIANGXIANG ||
                    mRoom.wanfatype == mRoom.YOUXIAN ||
                    mRoom.wanfatype == mRoom.HENGYANG ||
                    mRoom.wanfatype == mRoom.HENGDONG ||
                    mRoom.wanfatype == mRoom.SHIHUKA) {
                    this.userAct(HU, this.showNo);
                    return;
                }
            } else if (pao == true) {
                this.userAct(PAO, card);
            } else if (ti == true) {
                this.userAct(TI, card);
            } else if (wei == true) {
                this.userAct(WEI, card);
            } else {
                if (peng == true) actList.push(PENG);
                if (chi == true) actList.push(CHI);
                if (guo == true) actList.push(GUO);
                if (hu == true) actList.push(HU);
                this.showActions(actList);
            }
        },

        onTurnOut: function (event) {                  //出牌
            var data = event;

            var Notice = data.Notice;
            this.goTurnOut(data.Turn, data.Second, data.Seq, data.Freeze, Notice);
            //检查是否少牌
            this.checkIsShaoPai(data.Turn, data.Cards);
        },

        checkIsShaoPai: function (trun, cards, type) {
            //cards 里面不包含倾 啸 牌
            if (trun != gameData.uid || (cards && cards.length == 0)) {
                return;
            }
            var handList = this.cardList;
            var paiLen = 0;
            var paiArr = [];
            if (handList) {
                for (var i = 0; i < handList.length; i++) {
                    var _spriteList = handList[i];
                    if (_spriteList && _spriteList.length == 4
                        && _spriteList[0] == _spriteList[1]
                        && _spriteList[0] == _spriteList[2]
                        && _spriteList[0] == _spriteList[3]
                        && _spriteList[0] != 21) {
                        continue;
                    } else if (_spriteList && _spriteList.length == 3
                        && _spriteList[0] == _spriteList[1]
                        && _spriteList[0] == _spriteList[2]
                        && _spriteList[0] != 21) {
                        continue;
                    } else {
                        paiLen += _spriteList.length;
                        for (var j = 0; j < _spriteList.length; j++) {
                            paiArr.push(_spriteList[j]);
                        }
                    }
                }
            }
            if (paiLen != cards.length) {
                // showMessageBox('少牌了哦！！！！');
                if (type) {
                    network.sendPhz(5000, 'CheckHand/' + type + '/samePosition3/' + JSON.stringify(paiArr) + '/mRoom[CardList]:/' + JSON.stringify(mRoom['CardList']));
                } else {
                    network.sendPhz(5000, 'CheckHand/' + '33333' + '/samePosition2/' + JSON.stringify(paiArr) + '/mRoom[CardList]:/' + JSON.stringify(mRoom['CardList']));
                }
            }
        },

        goTurnOut: function (userId, seconds, seq, Freeze, Notice) {
            this.setTurnInOver();
            this.showCard.setVisible(false);
            this.nChiList.removeAllChildren();
            var turnPos = this.getUserPosIndex(userId);
            this.turnPos = turnPos;
            this.secondsLeft = 25;
            this.bigAction = null;

            if (turnPos == 0) {
                this.isTurnOut = true;
                this.isTurnIn = false;
                mRoom.outSeq = seq;

                var cards = mRoom['CardList'];
                if (cards && cards.length == 0) {
                    this.userShowCard(0, true);
                }
            }
            //冻结 Freeze
            if (userId == gameData.uid && Freeze && Freeze.length > 0) this.setFreezeCard(Freeze);
            //提示的牌 Notice


            if (userId == gameData.uid && Notice && Notice.length > 0) {
                this.Notice = Notice;
            } else {
                this.Notice = null;
            }
            // cc.log("Notice : " + Notice + "  this.Notice:" + this.Notice);

        },
        setNotice: function (notice) {
            this.Notice = notice;
        },
        setFreezeCard: function (Freeze) {
            this.Freeze = Freeze;
            if (Freeze) {
                var isFreeze = function (freezeCard) {
                    for (var i = 0; i < Freeze.length; i++) {
                        if (Freeze[i] == freezeCard) {
                            return true;
                        }
                    }
                    return false;
                };
                var cardList = this.nCards0.getChildren();
                for (var i = 0; i < cardList.length; i++) {
                    var card = cardList[i];
//                card.setGrayCard(isFreeze(card.data));
                }
            }
        },
        showLZCardAtPos: function (card, userPos, isMo) {
            this.showCardAtPos(card, userPos, isMo, true);
            this.scheduleOnce(function () {
                this.showCard.setVisible(false);
                if (userPos == 0 && !mRoom.isReplay) {
                    if (mRoom.isInOpenList(card) == false) {
                        //提过的亮张不要放进手牌  计算手里的牌数量
                        var cards = mRoom['CardList'];
                        var comboList = mAction.combos[0];
                        var comboNum = 0;
                        for (var s = 0; s < comboList.length; s++) {
                            comboNum = comboNum + comboList[s].cards.length;
                        }
                        if (cards && (cards.length + comboNum) != 21) {
                            //console.log(cards);
                            this.addCard(card);
                            var cardList = mCard.getCardList(cards);
                            //console.log(cardList);
                            this.cardList = cardList;
                            // this.setupCards();

                            if (movecard && positionBak && (this.isBeginTouch)) {
                                this.moveCardBack();
                            } else {
                                cc.sys.localStorage.setItem('Storage_handsCards', JSON.stringify(this.cardList));
                                this.setupCards();
                            }
                        }
                    }
                }
            }, 1);
            if (mRoom.isReplay) {
                //提过的亮张不要放进手牌  计算手里的牌数量
                var addLiangZhangCard = false;
                var cards = null;
                if (userPos == 0) {
                    cards = mRoom['CardList'];
                } else {
                    cards = mRoom['CardList' + userPos];
                }
                var comboList = mAction.combos[userPos];
                var comboNum = 0;
                for (var s = 0; s < comboList.length; s++) {
                    comboNum = comboNum + comboList[s].cards.length;
                }
                if (cards && (cards.length + comboNum) != 21) {
                    addLiangZhangCard = true;
                }
                if (userPos == 0) {
                    if (addLiangZhangCard)
                        mRoom['CardList'].push(card);
                    var cardList = mCard.getCardList(mRoom['CardList']);
                    this.cardList = cardList;
                    this.setupCards();
                } else {
                    if (addLiangZhangCard)
                        mRoom['CardList' + userPos].push(card);
                    this['cardList' + userPos] = mCard.getOtherCardList(mRoom['CardList' + userPos]);
                    this.setupOtherCards(userPos);
                }
            }
        },

        showCardAtPos: function (card, userPos, isMo, isLz) {
            if (isMo == undefined || isMo == null) isMo = false;
            if (card != 0) {
                this.playEffectByMap(card, gameData.sex);
            }
            this.showNo = card;
            this.showCard.setScale(1);
            this.showCard.setOpacity(255);
            this.showCard.setVisible(true);
            this.showCard.setData(this.showNo, null, 1);
            this.showCard.setMo(isMo);
            if (isLz) {
                mEffect.liangPai(this.showCard, userPos);
            } else {
                if (isMo) {
                    mEffect.moPai(this.showCard, userPos);
                } else {
                    mEffect.chuPai(this.showCard, userPos);
                    this.setDisconnect2(userPos);
                }
            }
            this.lastShowCard = [card, userPos, isMo, isLz];
        },
        playEffectByMap: function (card, sex) {
            // if (mRoom.wanfatype == mRoom.HENGYANG) {
            //     playEffect("paohuzi_pth_v" + card, sex);
            // } else {
            //     playEffect("paohuzi_v" + card, sex);
            // }
            playEffect('paohuzi_v' + card, sex);

        },
        playCPTPHEffect: function (cp, sex) {
            // if (mRoom.wanfatype == mRoom.HENGYANG) {
            //     playEffect("paohuzi_pth_v" + cp, sex);
            // } else {
            //     playEffect("paohuzi_v" + cp, sex);
            // }
            playEffect('paohuzi_v' + cp, sex);

        },
        playJSEffect: function (cp, sex) {
            playEffect('paohuzi_v' + cp, sex);
        },
        addOutCard: function (isCombo) {
            if (this.lastShowCard != null && this.lastShowCard[3] != true) { //不是亮张
                if (isCombo != true) {
                    var userPos = this.lastShowCard[1];
                    var card = this.lastShowCard[0];
                    var out = this['out' + userPos];
                    out.addCard(card, true, this.showCard);
                }
                this.lastShowCard = null;
            }
        },

        moCard: function () {
            if (mAction.leftCardCount > 0) {
                mAction.leftCardCount -= 1;
                this.txtCardCount.setString(mAction.leftCardCount);
            }
        },

        updateHX: function (userPos, handshuxi) {
            var txt = this['txtHX' + userPos];
            var txt_str = this['txtHX_value_' + userPos];
            var showHx = mAction.showHx[userPos];
            if (this._handshuxi && userPos == 0) {
                showHx += this._handshuxi;
            }
            if (mRoom.wanfatype == mRoom.LEIYANG || mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.SHIHUKA) {
                if (cc.sys.isObjectValid(txt))
                    txt.setString('胡子');
                txt_str.setString(showHx);
            } else if (mRoom.wanfatype == mRoom.YOUXIAN) {
                var newpos = (userPos + this.pos0) % this.playersNum;
                var scorenum = mRoom.InGameScore[newpos] || 0;
                if (cc.sys.isObjectValid(txt))
                    txt.setString('得分:' + scorenum);
            } else if (mRoom.wanfatype == mRoom.WEIMAQUE) {
                if (cc.sys.isObjectValid(txt))
                    txt.setString('硬息:' + showHx);
            }
            else {
                if (cc.sys.isObjectValid(txt))
                    txt.setString('胡息:' + showHx);
            }
        },
        hideImaAct: function () {
            this.imgAct.stopAllActions();
            this.imgAct.setOpacity(0);
            this.huAni.setOpacity(0);
        },
        tpwhEffect: function (tpwhNode, src, imgScale) {
            var clipper = function () {  //创建剪切区域
                var clipper = new cc.ClippingNode();
                var gameTitle = new cc.Sprite(src);
                // gameTitle.setScale(imgScale);
                clipper.setStencil(gameTitle);
                clipper.setAlphaThreshold(0);
                clipper.setContentSize(cc.size(gameTitle.getContentSize().width, gameTitle.getContentSize().height));
                return clipper;
            };

            tpwhNode.setScale(0);
            tpwhNode.runAction(cc.sequence(
                cc.scaleTo(0.1, 0.8 * imgScale, 1.2 * imgScale),
                cc.scaleTo(0.1, 1.1 * imgScale, 0.9 * imgScale),
                cc.scaleTo(0.05, 0.95 * imgScale, 1.05 * imgScale),
                cc.scaleTo(0.05, imgScale, imgScale),
                cc.callFunc(function () {
                        var clip = clipper();
                        var clipSize = cc.size(200, 80);
                        clip.setPosition(cc.p(tpwhNode.getContentSize().width / 2, tpwhNode.getContentSize().height / 2));
                        var gameTitle = new cc.Sprite(huzi.res.transparent_97x99_png);
                        var spark = new cc.Sprite(res.eff_spark_png);
                        // spark.setScale(imgScale);
                        clip.addChild(gameTitle, 1);
                        spark.setPosition(-tpwhNode.getContentSize().width / 2, 0);
                        clip.addChild(spark, 2);
                        tpwhNode.addChild(clip, 4);
                        var moveAction = cc.moveTo(.5, cc.p(clipSize.width, 0));
                        var seq = cc.sequence(moveAction);
                        spark.runAction(seq);
                    }
                )
            ));
        },
        showActAnimation: function (typ, userPos, count) {
            if (window.huzi_anniu_type === 2) {
                this.showImgAct(typ, userPos);
                return;
            }
            var animation_name = '';
            var ccsScene = ccs.load(res.PhzHu_json,  huzi.resPath);
            var tag = -1;
            switch (typ) {
                case mCard.comboTypes.chi:
                    tag = 2;
                    // if (count && count > 1) {
                    //     ccsScene = ccs.load(huzi.res.CHZ_xiahuo_json);
                    //     animation_name = 'xiahuo';
                    // } else {
                    ccsScene = ccs.load(huzi.res.CHZ_chi_json);
                    animation_name = 'chi';
                    // }
                    break;
                case mCard.comboTypes.chouwei:
                    ccsScene = ccs.load(huzi.res.CHZ_guoxiao_json);
                    animation_name = 'wei';
                    break;
                case mCard.comboTypes.pao:
                    ccsScene = ccs.load(huzi.res.CHZ_pao_json);
                    animation_name = 'pao';
                    break;
                case mCard.comboTypes.peng:
                    tag = 3;
                    ccsScene = ccs.load(huzi.res.CHZ_peng_json);
                    animation_name = 'peng';
                    break;
                case mCard.comboTypes.ti:
                    ccsScene = ccs.load(huzi.res.CHZ_qing_json);
                    animation_name = 'ti';
                    break;
                case mCard.comboTypes.wei:
                    ccsScene = ccs.load(huzi.res.CHZ_xiao_json);
                    animation_name = 'wei';
                    break;
                // case mCard.comboTypes.sishou:
                //     ccsScene = ccs.load(huzi.res.CHZ_sishou_json);
                //     animation_name = 'sishou';
                //     break;
                default:
                    animation_name = 'hu';
                    break;
            }
            var userNum = 3;
            if (mRoom.shouxing && mRoom.sxUserId > 0) {
                userNum = 4;
            }

            if (mRoom.getPlayerNum() == userNum || mRoom.erren || mRoom.sanren) {
                if (userPos == 0) {
                    this.aniAct.setPosition(cc.p(1280 / 2, 250 + 130));
                    for (var i = 0; i < this.listActBtn.length; i++) {
                        var bt = this.listActBtn[i];
                        if (bt.getTag() == tag) {
                            this.aniAct.setPosition(cc.p(bt.getPositionX() + this.nAction.getPositionX(), 95 + this.nAction.getPositionY()));
                        }
                    }
                } else if (userPos == 1) {
                    this.aniAct.setPosition(cc.p(1280 - 320, 500));
                } else {
                    this.aniAct.setPosition(cc.p(320, 500));
                }
            } else {
                if (userPos == 0) {
                    this.aniAct.setPosition(cc.p(1280 / 2, 250 + 130));
                } else if (userPos == 1) {
                    this.aniAct.setPosition(cc.p(1280 - 320, 250));
                } else if (userPos == 2) {
                    this.aniAct.setPosition(cc.p(1280 - 320, 500));
                } else {
                    this.aniAct.setPosition(cc.p(320, 500));
                }
            }
            this.aniAct.removeAllChildren();
            this.aniAct.setOpacity(200);

            if (!window.huzi_anniu_type) {
                window.huzi_anniu_type = cc.sys.localStorage.getItem('huzi_anniu_type') || '1';
                window.huzi_anniu_type = parseInt(window.huzi_anniu_type);
            }
            // 动画类型1《spine》
            if (window.huzi_anniu_type === 1 && animation_name !== '') {
                var zi_tx = playSpAnimation_hz('zi_tx', animation_name, false);
                if (cc.sys.isObjectValid(zi_tx)) {
                    zi_tx.x = this.aniAct.getContentSize().width / 2;
                    zi_tx.y = this.aniAct.getContentSize().height / 2;
                    this.aniAct.addChild(zi_tx);
                }
            }
            // 动画类型2《ccs》
            if (window.huzi_anniu_type === 2 && ccsScene.node) {
                var huani = ccsScene.node;
                huani.setPosition(cc.p(this.aniAct.getContentSize().width / 2, this.aniAct.getContentSize().height / 2));
                this.aniAct.addChild(huani);
                huani.runAction(ccsScene.action);
                ccsScene.action.play('action', false);
            }
            this.scheduleOnce(function () {
                this.aniAct.setOpacity(0);
            }, 0.4);
        },
        showImgAct: function (typ, userPos) {
            var that = this;
            var imgScale = 1.5;
            var img = '';
            var timeAdd = 0;
            switch (typ) {
                case mCard.comboTypes.chi:
                    img = 'chiSay.png';
                    break;
                case mCard.comboTypes.chouwei:
                    img = (mRoom.wanfatype == mRoom.GUILIN) ? 'guosaoSay.png' : 'weiSay.png';
                    break;
                case mCard.comboTypes.hu:
                    img = 'huSay.png';
                    timeAdd = 1.0;
                    break;
                case mCard.comboTypes.pao:
                    img = (mRoom.wanfatype == mRoom.GUILIN) ? 'kaiduoSay.png' : 'paoSay.png';
                    break;
                case mCard.comboTypes.peng:
                    img = 'pengSay.png';
                    break;
                case mCard.comboTypes.ti:
                    img = (mRoom.wanfatype == mRoom.CHEHUZI) ? 'tiSay_yz.png' : 'tiSay.png';
                    break;
                case mCard.comboTypes.wei:
                    img = (mRoom.wanfatype == mRoom.CHEHUZI) ? 'weiSay_yz.png' : 'weiSay.png';
                    break;
            }
            if (img != '') {
                // var src = 'res/paohuzi/' + img;
                var src = huzi.resPath+'dynamicRes/' + img;
                this.imgAct.setScale(imgScale);
                this.imgAct.setTexture(src);

                if (this.playersNum == 3) {
                    if (userPos == 0) {
                        this.imgAct.setPosition(1280 / 2, 400);
                    } else if (userPos == 1) {
                        this.imgAct.setPosition(1280 - 220, 550);
                    } else {
                        this.imgAct.setPosition(220, 550);
                    }
                } else if (this.playersNum == 2) {
                    if (userPos == 0) {
                        this.imgAct.setPosition(1280 / 2, 400);
                    } else if (userPos == 1) {
                        this.imgAct.setPosition(1280 - 220, 550);
                    }
                } else {
                    if (userPos == 0) {
                        this.imgAct.setPosition(1280 / 2, 370);
                    } else if (userPos == 1) {
                        this.imgAct.setPosition(1280 - 320, 250);
                    } else if (userPos == 2) {
                        this.imgAct.setPosition(1280 - 320, 500);
                    } else {
                        this.imgAct.setPosition(320, 500);
                    }
                }
                this.imgAct.removeAllChildren();
                if (typ == mCard.comboTypes.hu) {
                    if (window.huzi_anniu_type === 1) {
                        var zi_tx = playSpAnimation_hz('zi_tx', 'hu', false);
                        if (cc.sys.isObjectValid(zi_tx)) {
                            zi_tx.x = this.imgAct.getContentSize().width / 2;
                            zi_tx.y = this.imgAct.getContentSize().height / 2;
                            this.imgAct.addChild(zi_tx);
                            this.huAni.setPosition(cc.p(this.imgAct.getPositionX(), this.imgAct.getPositionY()));
                            this.huAni.setOpacity(0);
                        }
                    } else {
                        //var ccsScene = ccs.load("res/PhzHu.json", "res/");
                        var ccsScene = ccs.load(res.PhzHu_json, huzi.resPath);
                        var huani = ccsScene.node;
                        // if (cc.sys.isObjectValid(huani)) {
                        huani.setScale(1.2);
                        huani.setPosition(cc.p(this.imgAct.getContentSize().width / 2, this.imgAct.getContentSize().height / 2));
                        this.imgAct.addChild(huani);
                        huani.runAction(ccsScene.action);
                        ccsScene.action.play('action', true);
                        this.huAni.setPosition(cc.p(this.imgAct.getPositionX(), this.imgAct.getPositionY()));
                        this.huAni.setOpacity(0);
                        // }
                    }
                } else {
                    this.tpwhEffect(this.imgAct, src, imgScale);
                }
                this.imgAct.setOpacity(255);

                // //重放的胡牌  一直存在,不消失
                if (typ == mCard.comboTypes.hu) {
                    if (!mRoom.isReplay) {
                        var seq = cc.sequence(
                            cc.delayTime(.5),
                            cc.fadeOut(0.1),
                            cc.callFunc(function () {
                                // var hu = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'huSay.png');
                                // that.huNode.setPosition(that.imgAct.getPosition());
                                // that.huNode.addChild(hu);
                                // that.imgAct.removeAllChildren();
                                that.huAni.setOpacity(200);
                            })
                        );
                        this.imgAct.runAction(seq);
                    }
                } else {
                    var seq = cc.sequence(
                        cc.delayTime(.5),
                        cc.fadeOut(0.1),
                        cc.callFunc(this.imgAct.removeAllChildren())
                    );
                    this.imgAct.runAction(seq);
                }
            }
        },

        onBroadCast: function (event) {               //广播操作
            var that = this;
            var data = event;
            // console.log(data);
            var action = data.Action;
            var actList = action.split('/');
            var userId = actList[0];
            var actStatus = actList[1];
            var actName = actList[2];
            var card = parseInt(actList[3]);
            var seq = parseInt(actList[4]);
            var info = '';
            if (actList.length > 5)
                info = actList[5];
            //mRoom.seq = seq;
            var ScoreChange = data.ScoreChange;

            if (isNaN(card)) {
                that.sendLogTo(null, null, null, action);
                return;
            }

            var userPos = this.getUserPosIndex(userId);
            var ismyself = false;
            if (userPos == 0) {
                ismyself = true;
            }
            if (actStatus == 1) {
                //设置在线
                this.setDisconnect(userId, false);

                switch (actName) {
                    case 'liangzhang':
                        mRoom.inSeq = 0;
                        this.showLZCardAtPos(card, userPos, true);
                        this.networkStop();
                        this.scheduleOnce(function () {
                            network.start();
                        }, 1.5);
                        break;
                    case 'ShowCard':
                        this.networkStop();
                        this.scheduleOnce(function () {
                            network.start();
                        }, 0.5);
                        this.setSameCardShow(card, false);
                        this.showCardAtPos(card, userPos, false);
                        if (userPos == 0 || mRoom.isReplay) {
                            var deleteCards = [card];
                            this.removeCards(deleteCards, userPos, this.outCardColumn, this.outCardRow);
                            this.outCardColumn = null;
                            this.outCardRow = null;
                        }
                        if (card == 0) {
                            this.playEffectByMap(card.toString(), gameData.sex);
                        }
                        break;
                    case 'mo':
                        this.networkStop();
                        this.addOutCard(false);
                        var that = this;
                        var action = null;
                        //解决回放时，当有提牌时棋牌区也出现所提的牌，导致出现5张相同的牌
                        if (mRoom.isReplay) {
                            action = cc.delayTime(0.3);
                        } else {
                            action = cc.delayTime(0.6);
                        }
                        if (cc.sys.isObjectValid(this)) {
                            this.runAction(cc.sequence(
                                action,
                                cc.callFunc(function () {
                                    that.turnPos = userPos;
                                    that.showCardAtPos(card, userPos, true);
                                    that.moCard();
                                }),
                                cc.delayTime(0.6),
                                cc.callFunc(function () {
                                    network.start();
                                })
                            ));
                        }
                        break;
                    case 'bakuai':
                        this.addOutCard(false);
                        //this.showCardAtPos(card, userPos);
                        this.moCard();
                        if (userPos == 0) {
                            this.addCard(card);
                        }
                        break;
                    case 'peng':
                        that.addOutCard(true);
                        var cardList = [card, card, card];
                        var open = that['open' + userPos];
                        cc.log('peng ... userPos = ' + userPos);
                        cc.log('peng ... open = ' + open);
                        if (open && open.addCards) {
                            try {
                                open.addCards(cardList, mCard.comboTypes.peng);
                                var _result = mEffect.chiPai(open, userPos);
                                if (_result == 'invalid') {
                                    that.sendLogTo(open, cardList, userPos, mCard.comboTypes.peng);
                                }
                            } catch (e) {
                                that.sendLogTo(open, cardList, userPos, mCard.comboTypes.peng);
                            }
                        }
                        that.updateHX(userPos);
                        that.showCard.setVisible(false);

                        that.showActAnimation(mCard.comboTypes.peng, userPos);
                        // that.showImgAct(mCard.comboTypes.peng, userPos);
                        if (userPos == 0 || mRoom.isReplay) {
                            var deleteCards = [card, card, card];
                            if (mRoom.wanfatype == mRoom.WEIMAQUE) deleteCards = [card, card];
                            that.removeCards(deleteCards, userPos);
                        }
                        this.playCPTPHEffect('peng', gameData.sex);
                        //攸县玩法  显示得分
                        this.showDefen(ScoreChange);
                        break;
                    case 'chi':
                        that.addOutCard(true);
                        that.nChiList.removeAllChildren();
                        var cardList = info.split(',');
                        var open = that['open' + userPos];
                        var count = cardList.length / 3;
                        for (var i = 0; i < count; i++) {
                            var combo = [];
                            var index = i * 3;
                            combo.push(cardList[index]);
                            combo.push(cardList[index + 1]);
                            combo.push(cardList[index + 2]);

                            var comboTyp = mCard.getComboType(combo);
                            // open.addCards-(combo, comboTyp);
                            //吃的第几张牌需要特殊现实   王常春 2016-7-8 add
                            //吃的放在第一个位置
                            for (var x = 0; x < combo.length; x++) {
                                if (parseInt(card) == parseInt(combo[x])) {
                                    var tmp = combo[x];
                                    for (var y = x + 1; y < 3; y++) {
                                        combo[y - 1] = combo[y];
                                    }
                                    combo[2] = tmp;
                                }
                            }
                            try {
                                open.addCards(combo, comboTyp, false);
                            } catch (e) {
                                that.sendLogTo(open, combo, userPos, mCard.comboTypes.chi);
                                // var _open = cc.sys.isObjectValid(open);
                                // var _addcards = false;
                                // var _combo = combo;
                                // var _comboTyp = comboTyp;
                                // if (_open) {
                                //     _addcards = !!open.addCards;
                                // }
                                // if (!!_combo) {
                                //     _combo = JSON.stringify(combo);
                                // }
                                //
                                // var _txt = 'open_addCards_0, _open' + _open
                                //     + ', _addcards' + _addcards
                                //     + ', userPos' + userPos
                                //     + ', _combo' + _combo
                                //     + ', _comboTyp' + _comboTyp;
                                // http.uploadErrorFileToOSS(_txt);
                            }
                        }
                        cc.log('open = ' + open);
                        cc.log('userPos = ' + userPos);
                        var _result = mEffect.chiPai(open, userPos);
                        if (_result == 'invalid') {
                            that.sendLogTo(open, cardList, userPos, mCard.comboTypes.chi);
                        }
                        that.updateHX(userPos);
                        that.showCard.setVisible(false);

                        that.showActAnimation(mCard.comboTypes.chi, userPos, count);
                        // that.showImgAct(mCard.comboTypes.chi, userPos);
                        if (userPos == 0 || mRoom.isReplay) {
                            var removeCards = mCard.copyCards(cardList);
                            for (var i = 0; i < removeCards.length; i++) {
                                if (removeCards[i] == card) {
                                    removeCards.splice(i, 1);
                                    break;
                                }
                            }
                            that.removeCards(removeCards, userPos);
                        }
                        if (mRoom.wanfatype == mRoom.GUILIN) {
                            this.playCPTPHEffect('chi', gameData.sex);
                        } else {
                            if (count > 1) {
                                this.playCPTPHEffect('bi', gameData.sex);
                            } else {
                                this.playCPTPHEffect('chi', gameData.sex);
                            }
                        }
                        break;
                    case 'ti':
                        this.networkStop();
                        this.scheduleOnce(function () {
                            network.start();
                        }, 0.5);

                        that.addOutCard(true);
                        var cardList = [card, card, card, card];
                        var isOpen = false;

                        //info == true牌桌上的偎
                        if (info == 'true') {
                            isOpen = true;
                        }
                        var open = that['open' + userPos];
                        try {
                            open.addCards(cardList, mCard.comboTypes.ti, isOpen);
                            mEffect.chiPai(open, userPos, true);
                        } catch (e) {
                            var _open = cc.sys.isObjectValid(open);
                            var _addcards = false;
                            var _combo = cardList;
                            var _comboTyp = mCard.comboTypes.wei;
                            if (_open) {
                                _addcards = !!open.addCards;
                            }
                            if (!!cardList) {
                                _combo = JSON.stringify(cardList);
                            }

                            var _txt = 'open_addCards_6 _open' + _open
                                + ', _addcards' + _addcards
                                + ', userPos' + userPos
                                + ', _combo' + _combo
                                + ', _comboTyp' + _comboTyp;
                            http.uploadErrorFileToOSS(_txt);
                        }
                        that.updateHX(userPos);
                        that.showCard.setVisible(false);//add hide

                        that.showActAnimation(mCard.comboTypes.ti, userPos);
                        // that.showImgAct(mCard.comboTypes.ti, userPos);
                        if ((userPos == 0 && isOpen == false) || mRoom.isReplay) {
                            that.isBeginTouch = true;
                            var deleteCards = [card, card, card, card];
                            // cc.log("ti-----------1");
                            if (movecard && cc.sys.isObjectValid(movecard) && positionBak && (that.isBeginTouch)) {
                                // cc.log("ti-----------2");
                                that.moveCardBack(deleteCards, userPos);
                            } else {
                                that.removeCards(deleteCards, userPos);
                            }
                        }

                        this.playCPTPHEffect('ti', gameData.sex);
                        //攸县玩法  显示得分
                        this.showDefen(ScoreChange);
                        break;
                    case 'pao':
                        that.addOutCard(true);
                        this.networkStop();
                        this.scheduleOnce(function () {
                            network.start();
                        }, 0.5);

                        var cardList = [card, card, card, card];
                        var isOpen = false;
                        if (info == 'true') {
                            isOpen = true;
                        }
                        var open = that['open' + userPos];
                        try {
                            open.addCards(cardList, mCard.comboTypes.pao, isOpen);
                            mEffect.chiPai(open, userPos);
                        } catch (e) {
                            var _open = cc.sys.isObjectValid(open);
                            var _addcards = false;
                            var _combo = cardList;
                            var _comboTyp = mCard.comboTypes.pao;
                            if (_open) {
                                _addcards = !!open.addCards;
                            }
                            if (!!cardList) {
                                _combo = JSON.stringify(cardList);
                            }

                            var _txt = 'open_addCards_5, _open' + _open
                                + ', _addcards' + _addcards
                                + ', userPos' + userPos
                                + ', _combo' + _combo
                                + ', _comboTyp' + _comboTyp;
                            http.uploadErrorFileToOSS(_txt);
                        }
                        that.updateHX(userPos);
                        that.showCard.setVisible(false);

                        that.showActAnimation(mCard.comboTypes.pao, userPos);
                        // that.showImgAct(mCard.comboTypes.pao, userPos);
                        if ((userPos == 0 && isOpen == false) || mRoom.isReplay) {
                            that.isBeginTouch = true;
                            var deleteCards = [card, card, card];
                            // cc.log("pao-----------1");
                            if (movecard && cc.sys.isObjectValid(movecard) && positionBak && (that.isBeginTouch)) {
                                // cc.log("pao-----------2");
                                that.moveCardBack(deleteCards, userPos);
                            } else {
                                that.removeCards(deleteCards, userPos);
                            }
                        }
                        this.playCPTPHEffect('pao', gameData.sex);
                        //攸县玩法  显示得分
                        this.showDefen(ScoreChange);
                        break;
                    case 'wei':
                        this.networkStop();
                        this.scheduleOnce(function () {
                            network.start();
                        }, 0.5);
                        that.showCard.setVisible(true);

                        this.scheduleOnce(function () {
                            that.showCard.setVisible(false);
                        }, .25);
                        that.addOutCard(true);
                        var cardList = [card, card, card];
                        var open = that['open' + userPos];
                        try {
                            open.addCards(cardList, mCard.comboTypes.wei, false);
                            mEffect.chiPai(open, userPos, true);
                        } catch (e) {
                            var _open = cc.sys.isObjectValid(open);
                            var _addcards = false;
                            var _combo = cardList;
                            var _comboTyp = mCard.comboTypes.wei;
                            if (_open) {
                                _addcards = !!open.addCards;
                            }
                            if (!!cardList) {
                                _combo = JSON.stringify(cardList);
                            }

                            var _txt = 'open_addCards_4, _open' + _open
                                + ', _addcards' + _addcards
                                + ', userPos' + userPos
                                + ', _combo' + _combo
                                + ', _comboTyp' + _comboTyp;
                            http.uploadErrorFileToOSS(_txt);
                        }
                        that.updateHX(userPos);
                        that.showCard.setVisible(false);//add hide

                        that.showActAnimation(mCard.comboTypes.wei, userPos);
                        // that.showImgAct(mCard.comboTypes.wei, userPos);
                        if (userPos == 0 || mRoom.isReplay) {
                            that.isBeginTouch = true;
                            var deleteCards = [card, card, card];
                            if (mRoom.wanfatype == mRoom.WEIMAQUE) deleteCards = [card, card];
                            // cc.log("wei-----------1");
                            if (movecard && cc.sys.isObjectValid(movecard) && positionBak && (that.isBeginTouch)) {
                                // cc.log("wei-----------2");
                                that.moveCardBack(deleteCards, userPos);
                            } else {
                                that.removeCards(deleteCards, userPos);
                            }
                        }
                        this.playCPTPHEffect('wei', gameData.sex);
                        //攸县玩法  显示得分
                        this.showDefen(ScoreChange);
                        break;
                    case 'chouwei':
                        this.networkStop();
                        this.scheduleOnce(function () {
                            network.start();
                        }, 0.5);

                        that.addOutCard(true);
                        var cardList = [card, card, card];
                        var open = that['open' + userPos];
                        if (open && open.addCards) {
                            try {
                                open.addCards(cardList, mCard.comboTypes.chouwei, false);
                                mEffect.chiPai(open, userPos, true);
                            } catch (e) {
                                var _open = cc.sys.isObjectValid(open);
                                var _addcards = false;
                                var _combo = cardList;
                                var _comboTyp = mCard.comboTypes.chouwei;
                                if (_open) {
                                    _addcards = !!open.addCards;
                                }
                                if (!!cardList) {
                                    _combo = JSON.stringify(cardList);
                                }

                                var _txt = 'open_addCards_3, _open' + _open
                                    + ', _addcards' + _addcards
                                    + ', userPos' + userPos
                                    + ', _combo' + _combo
                                    + ', _comboTyp' + _comboTyp;
                                http.uploadErrorFileToOSS(_txt);
                            }
                        }
                        that.updateHX(userPos);
                        that.showCard.setVisible(false);//add hide

                        that.showActAnimation(mCard.comboTypes.chouwei, userPos);
                        // that.showImgAct(mCard.comboTypes.chouwei, userPos);
                        if (userPos == 0 || mRoom.isReplay) {
                            that.isBeginTouch = true;
                            var deleteCards = [card, card, card];
                            if (mRoom.wanfatype == mRoom.WEIMAQUE) deleteCards = [card, card];
                            if (movecard && cc.sys.isObjectValid(movecard) && positionBak && (that.isBeginTouch)) {
                                that.moveCardBack(deleteCards, userPos);
                            } else {
                                that.removeCards(deleteCards, userPos);
                            }
                        }
                        if (mRoom.wanfatype == mRoom.GUILIN) {
                            this.playCPTPHEffect('chouwei', gameData.sex);
                        } else {
                            this.playCPTPHEffect('wei', gameData.sex);
                        }
                        //攸县玩法  显示得分
                        this.showDefen(ScoreChange);
                        break;
                    case 'hu':
                        // cc.log("check game hu +++++");
                        if (info != null && info.length > 0) {
                            this.gameOverHuInfo = JSON.parse(info);
                        }
                        //this.processGameOver();
                        this.showImgAct(mCard.comboTypes.hu, userPos);
                        //this.playCoinFlyAnimOfHu(userPos);
                        break;
                    default :
                        break;
                }
            } else {
                // this.setTurnInOver();


                // if (this.bigAction != null) {
                //     var act = mAction.getActionByString(actName);
                //     if (act == TI || act == WEI || act == CHOUWEI) {
                //         //提偎 不自动过牌
                //     } else {
                //         if (this.lastShowCard != null && this.bigAction != null) {
                //             var moPos = this.lastShowCard[1];
                //             if (moPos != 0 && act == this.bigAction) {    //最高级操作相同时
                //                 var needAuto = false;
                //                 if (moPos == userPos) {                   //摸牌人操作
                //                     needAuto = true;
                //                 } else {
                //                     if (moPos == 1 && userPos == 2) {     //摸牌人是下家
                //                         needAuto = true;
                //                     }
                //                 }
                //                 if (needAuto == true) {
                //                     //自动过牌
                //                     mRoom.inSeq = seq;
                //                     this.userAct(GUO, card, true);
                //                     // this.setTurnInOver();
                //                 }
                //             } else if (act < this.bigAction) {             //最高级操作小于广播
                //                 //自动过牌
                //                 // mRoom.inSeq = seq;
                //                 // this.userAct(GUO, card, true);
                //                 this.setTurnInOver();
                //             }
                //         }
                //     }
                // }
            }

            if (userId.length > 10)
                userId = userId.substr(0, 5);

            if (seq == null) {
                cc.log('seq is null');
            }
        },
        sendLogTo: function (open, cardList, userPos, typ) {
            var _open = cc.sys.isObjectValid(open);
            var _addcards = false;
            var _combo = cardList;
            var _comboTyp = typ;
            if (_open) {
                _addcards = !!open.addCards;
            }
            if (!!cardList) {
                _combo = JSON.stringify(cardList);
            }

            var _txt = 'open_addCards_2, _open' + _open
                + ', _addcards' + _addcards
                + ', userPos' + userPos
                + ', _combo' + _combo
                + ', _comboTyp' + _comboTyp;
            http.uploadErrorFileToOSS(_txt);
        },
        playCoinFlyAnimOfHu: function (row) {
            var head0 = $('node.info0.head0', this.playersInfo);
            var head1 = $('node.info1.head1', this.playersInfo);
            var head2 = $('node.info2.head2', this.playersInfo);
            //var head3 = $("node.info3.head3", this.playersInfo);
            switch (row) {
                case 0:
                    this.playCoinsFlyAnim(head1, head0, 10);
                    this.playCoinsFlyAnim(head2, head0, 10);
                    //this.playCoinsFlyAnim(head3, head0, 10);
                    break;
                case 1:
                    this.playCoinsFlyAnim(head0, head1, 10);
                    this.playCoinsFlyAnim(head2, head1, 10);
                    //this.playCoinsFlyAnim(head3, head1, 10);
                    break;
                case 2:
                    this.playCoinsFlyAnim(head0, head2, 10);
                    this.playCoinsFlyAnim(head1, head2, 10);
                    //this.playCoinsFlyAnim(head3, head2, 10);
                    break;
                case 3:
                    this.playCoinsFlyAnim(head0, head3, 10);
                    this.playCoinsFlyAnim(head1, head3, 10);
                    //this.playCoinsFlyAnim(head2, head3, 10);
                    break;
                default:
                    break;
            }

        },
        networkStop: function () {
            if (mRoom.isReplay)
                return;
            network.stop();
        },
        showPlayerInfoPanel: function (idx) {
            if (window.inReview || this.getRoomState() != ROOM_STATE_ONGOING)
                return;

            if (!position2playerArrIdx || !position2playerArrIdx[idx])
                this.setPosition2Player();

            if (position2playerArrIdx[idx] >= gameData.players.length)
                return;

            //新版表情3
            var that = this;
            var PlayerInfo = gameData.players[position2playerArrIdx[idx]];
            network.send(3018, {cmd: 'queryEmoji', uid: gameData.uid, room_id: gameData.roomId, showOption: 32767});
            // that.addChild(new PlayerInfoLayerInGame(PlayerInfo));
            showWindow('PlayerInfoInGameWindow', PlayerInfo, that);
        },

        moveCardBack: function (deleteCards, userPos) {
            var that = this;
            console.log('=====正在移牌，先置回后在处理 removeCards');
            try {
                if (zorderBak) movecard.setLocalZOrder(zorderBak);
                movecardTmp.setVisible(false);
                movecard.stopAllActions();
                movecard.setPosition(movecardTmp.getPosition());
                movecard.setOpacity(255);
                movecard.runAction(cc.sequence(
                    cc.moveTo(0.1, positionBak),
                    cc.callFunc(function (sender) {
                        movexy = null;
                        movetoxy = null;
                        movetoxybak = null;
                        // cc.log('moveCardBack-----------callFunc');
                        movecard = null;
                        positionBak = null;
                        movetocardArr = [];
                        movetocardPosArr = [];
                        that.isMoving = false;
                        // that.isBeginTouch = false;
                        sender = null;
                    })
                ));

                setTimeout(function () {
                    movexy = null;
                    movetoxy = null;
                    movetoxybak = null;
                    // cc.log('moveCardBack-----setTimeout------callFunc');
                    movecard = null;
                    positionBak = null;
                    movetocardArr = [];
                    movetocardPosArr = [];
                    that.isMoving = false;
                }, 100);

                that.checkHandCards();
            } catch (e) {
                network.sendPhz(5000, 'moveCardBack/' + e.toString());
            }

            if (deleteCards) {
                that.scheduleOnce(function () {
                    // that.isBeginTouch = false;
                    that.removeCards(deleteCards, userPos);
                }, .12);
            } else {
                that.scheduleOnce(function () {
                    that.setupCards();
                }, .12);
                network.sendPhz(5000, 'moveCardBack/deleteCardsIsNull');
            }
        },

        checkHandCards: function (type, info) {
            // return;
            if (type == 'movingError') {
                console.log('==========movingError=====================');
                network.sendPhz(5000, 'CheckHand/' + type + '/movingError/' + info);
                return;
            }

            //出牌检测牌是否重叠（位置相同） 和 牌是否有显隐的bug
            var cardsList = this.nCards0.getChildren();
            var posArr = [];
            var tag = [];
            for (var i = 0; i < cardsList.length; i++) {
                var _cardSprite = cardsList[i];
                if (_cardSprite.getName() == 'movecardTmp') {
                    continue;
                }
                var isBreak = false;
                var _data = '';
                var pos = _cardSprite.getPosition();

                for (var j = 0; j < posArr.length; j++) {
                    if (pos.x == posArr[j].x && pos.y == posArr[j].y) {
                        for (var m = 0; m < cardsList.length; m++) {
                            _data += (cardsList[m].data + ',');
                        }
                        network.sendPhz(5000, 'CheckHand/' + type + '/samePosition/' + _data);
                        // showMessageBox('有相同位置的牌出现了this.nCards0.length:' + cardsList.length + '  this.cardlistlen:' + this.cardList.length);
                        isBreak = true;
                        break;
                    }
                }
                if (isBreak) {
                    console.log('您手中的牌有重叠的了');
                    // showMessageBox('您手中的牌有重叠的了，请退出冲进！！！');
                    this.setupCards();
                    break;
                }
                // tag.push(_cardSprite.getTag());
                posArr.push(pos);
            }


            for (var i = 0; i < cardsList.length; i++) {
                var _cardSprite = cardsList[i];
                if (cc.sys.isObjectValid(_cardSprite) && _cardSprite.getName() == 'movecardTmp') {
                    continue;
                }
                if (cc.sys.isObjectValid(_cardSprite) && !_cardSprite.isVisible()) {
                    network.sendPhz(5000, 'CheckHand/' + type + '/cardVisible/false');
                    _cardSprite.setVisible(true);
                }
            }

        },

        showDefen: function (ScoreChange) {
            if (ScoreChange && ScoreChange.length > 0) {
                var scoreList = ScoreChange.split('/');
                if (scoreList && scoreList.length == 8) {
                    for (var i = 0; i < this.playersNum; i++) {
                        var defenNum = scoreList[(this.pos0 + i) % 4 + 4];
                        var zongfenNum = scoreList[(this.pos0 + i) % 4];
                        this['txtHX' + i].setString('[得分:' + zongfenNum + ' ]');
                        mRoom.InGameScore[i] = zongfenNum;
                        if (defenNum && parseInt(defenNum) != 0) {
                            var row = i;
                            var head = $('node.info' + row + '.head' + row, this.playersInfo);
                            var defen = head.getChildByName('defen');
                            if (!defen) {
                                defen = new cc.LabelBMFont('', 'res/image/fonts/zongjiesuan_jifen_fnt.fnt');
                                defen.setName('defen');
                                defen.setScale(0.85);
                                defen.setPosition((row == 0 || row == 1) ? cc.p(50, 0) : cc.p(50, -20));
                                if (defenNum) defen.setString((parseInt(defenNum) > 0) ? '+' + defenNum : defenNum);
                                head.addChild(defen);
                            }
                            defen.stopAllActions();
                            defen.runAction(cc.sequence(
                                cc.moveBy(1, 0, 100).easing(cc.easeIn(1.5))
                                , cc.moveBy(1, 0, 50).easing(cc.easeOut(1.5))
                                , cc.fadeOut(1)
                                , cc.callFunc(function (sender) {
                                    sender.removeFromParent();
                                })
                            ));
                        }
                    }
                }
            }
        },
        userShowCard: function (card, isAuto, row, column, target, position) {
            var that = this;
            this.outCardRow = row + 1;
            this.outCardColumn = column + 1;

            if (mRoom.wanfatype == mRoom.CHEHUZI && card == 21) {
                return;
            }

            //放炮罚玩法  射跑的判断
            if (mRoom.wanfatype == mRoom.FANGPAOFA ||
                mRoom.wanfatype == mRoom.LEIYANG ||
                mRoom.wanfatype == mRoom.SHAOYANGBOPI ||
                mRoom.wanfatype == mRoom.SHAOYANG ||
                mRoom.wanfatype == mRoom.XIANGXIANG ||
                mRoom.wanfatype == mRoom.CHENZHOU ||
                mRoom.mingwei == true) {
                var isShepao = false;
                for (var i = 1; i <= this.playersNum; i++) {
                    if (mAction.combos[i] && mAction.combos[i].length > 0) {
                        for (var j = 0; j < mAction.combos[i].length; j++) {
                            if ((mAction.combos[i][j].typ == mCard.comboTypes.chouwei
                                    || mAction.combos[i][j].typ == mCard.comboTypes.wei)
                                && parseInt(mAction.combos[i][j].cards[0]) == parseInt(card)) {
                                isShepao = true;
                                that._isShePao = true;
                                break;
                            }
                        }
                    }
                }
                if (isShepao) {
                    showMessageBox('射跑，之后您将无法吃、碰，请问是否出牌?', function () {
                        // that.fingerAni(false);
                        network.sendPhz(5000, 'ShowCard/' + card + '/' + mRoom.outSeq);
                        that.tipLine.setVisible(false);
                        that._isShePao = null;
                        //点击确定后，需将isTurnOut的标记置为false，如果有手指滑动动画，也需隐藏。
                        that.isTurnOut = false;
                        that.fingerAni(false);
                    }, function () {

                        movecard = target;
                        // cc.log('----------------A: isShepao' + movecard.data);
                        positionBak = position;

                        if (movecard) {
                            that._needShowTingTip = true;
                            movecard.setPosition(positionBak);
                            that.setupCards();
                            that.setSameCardShow(movecard.data, false);
                        }
                        movecard = null;
                        positionBak = null;
                        that._isShePao = null;
                    });
                    return;
                }
            }
            //耒阳玩法  有234 吃了别人的5，出2时，提示
            if (mRoom.wanfatype == mRoom.LEIYANG) {
                if (this.Notice && this.Notice.length > 0 && this.Notice.indexOf(card) >= 0) {
                    showMessageBox('吃边打边，本局只能胡红胡、黑胡、点朱和无胡，确定出牌吗?', function () {
                        network.sendPhz(5000, 'ShowCard/' + card + '/' + mRoom.outSeq);
                        that.tipLine.setVisible(false);
                        that._isShePao = null;
                        that.Notice = null;
                        //点击确定后，需将isTurnOut的标记置为false，如果有手指滑动动画，也需隐藏。
                        that.isTurnOut = false;
                        that.fingerAni(false);
                    }, function () {
                        // if (that.movecard) {
                        //     that.movecard.setPosition(that.positionBak || cc.p(0, 0));
                        //     that.setSameCardShow(that.movecard.data, false);
                        // }
                        movecard = target;
                        positionBak = position;

                        if (movecard) {
                            that._needShowTingTip = true;
                            movecard.setPosition(positionBak || cc.p(0, 0));
                            that.setupCards();
                            that.setSameCardShow(movecard.data, false);
                        }
                        movecard = null;
                        positionBak = null;
                        that._isShePao = null;
                    });
                    return;
                }
            }
            if (isAuto == true) {
                this.scheduleOnce(function () {
                    that.fingerAni(false);
                    network.sendPhz(5000, 'ShowCard/' + card + '/' + mRoom.outSeq);
                    that.tipLine.setVisible(false);
                }, 1);
            } else {
                that.fingerAni(false);
                //偎麻雀判断  是不是冻结的牌,冻结的牌不能出
                if (mRoom.wanfatype == mRoom.WEIMAQUE) {
                    if (that.Freeze && that.Freeze.length > 0 && that.Freeze.indexOf(card) >= 0) {
                        return;
                    }
                }
                network.sendPhz(5000, 'ShowCard/' + card + '/' + mRoom.outSeq);
                that.tipLine.setVisible(false);
            }

            this.setTurnOutOver();

            if (mRoom.outSeq == null) {
                cc.log('outSeq is null');
            }
        },

        userAct: function (act, card, target, info) {
            var actString = mAction.getActionString(act);
            if (info != null) {
                info = '/' + info;
            } else {
                info = '';
            }

            if (actString == 'none') {
                actString = 'guo';
            }
            network.sendPhz(5000, 'EatCard/' + actString + '/' + card + '/' + mRoom.inSeq + info);

            this.setTurnInOver();
        },

        setTurnOutOver: function () {
            this.isTurnOut = false;
            this.secondsLeft = 0;
        },

        setTurnInOver: function () {
            var that = this;
            that.nAction.runAction(
                cc.sequence(
                    cc.scaleTo(0.1, 0, 0),
                    cc.callFunc(function () {
                        that.nAction.setScale(1);
                        that.nAction.setVisible(false);
                    })
                )
            );
            // that.nAction.setVisible(false);
            that.nChiList.removeAllChildren();
            that.secondsLeft = 0;
            that.isTurnIn = false;
        },

        onUserJoin: function (event) {
            var data = event;
            if (data.Head.Result != null && data.Head.Result == -1) {
            } else {
                gameData.players = data['Users'];
                this.setupPlayers();
                var offLines = data.OfflineList;
                for (var i = 0; i < offLines.length; i++) {
                    var userId = Math.abs(offLines[i]);
                    this.setDisconnect(userId, offLines[i] < 0);
                }
            }
            this.setPosition2Player();
            eventManager.dispatchEvent(EventKey.ClubPlayerEnterExit, gameData.players);
        },
        //掉线
        onUserDisconnect: function (event) {
            var data = event;
            var flag = false;
            if (data.ConnectStatus == 'disconnected') {
                flag = true;
            } else if (data.ConnectStatus == 'online') {
                flag = false;
            }
            this.setDisconnect(data.UserID, flag);
        },
        onUserKick: function (event) {

        },
        Pls_Disconnect_MSG: function (event) {
            // var data = event;
            //this.removeChildByTag(111);
            mRoom['CardList'] = null;
        },

        onEatCard: function (event) {
            // var data = event;
            var data = event;
            this.showReplayAction(data);
        },

        onStatusChange: function (event) {
            // var data = event;
            var data = event;
            //UserID
            if (data.Status == 'ReadyForNext') {
                //断线回来
            }
            this.setDisconnect(data.UserID, false);
            this.setReady(data.UserID, true);
        },

        onPreAction: function (event) {
            var data = event;

            // cc.log("onPreAction   +++++", data.Action, data.Card);
        },

        onGameOver: function (event) {
            var data = event;
            //游戏结束时重置听牌提示
            this._lastTingEvent = null;

            this.showCard.setVisible(false);
            if (mRoom.isClean != true) {
                this.gameOverData = data;
                this.processGameOver();
                //显示别人的手牌
                if (mRoom.isReplay != true) {
                    var users = gameData.players;
                    for (var i = 0; i < data.Users.length; i++) {
                        if (this.playersNum == 3) {
                            if (users[this.pos1] && data.Users[i].UserID == users[this.pos1].ID) {
                                mRoom['CardList1'] = data.Users[i].Hand;
                                this.cardList1 = mCard.getOtherCardList(mRoom['CardList1']);
                                this.setupOtherCards(1);
                                this.open1.setWeiColor(1);
                            } else if (users[this.pos2] && data.Users[i].UserID == users[this.pos2].ID) {
                                mRoom['CardList2'] = data.Users[i].Hand;
                                this.cardList2 = mCard.getOtherCardList(mRoom['CardList2']);
                                this.setupOtherCards(2);
                                if (this.open2 && this.open2.setWeiColor)
                                    this.open2.setWeiColor(2);
                            }
                        } else if (this.playersNum == 2) {
                            if (users[this.pos1] && data.Users[i].UserID == users[this.pos1].ID) {
                                mRoom['CardList1'] = data.Users[i].Hand;
                                this.cardList1 = mCard.getOtherCardList(mRoom['CardList1']);
                                this.setupOtherCards(1);
                                this.open0.setWeiColor(1);
                            } else if (users[this.pos2] && data.Users[i].UserID == users[this.pos2].ID) {
                                mRoom['CardList2'] = data.Users[i].Hand;
                                this.cardList2 = mCard.getOtherCardList(mRoom['CardList2']);
                                this.setupOtherCards(2);
                                this.open1.setWeiColor(2);
                            }

                            if (this.isErrenwanSipai()) {
                                if (data.Sipai) {
                                    mRoom['CardList2'] = data.Sipai;
                                    this.cardList2 = mCard.getOtherCardList(mRoom['CardList2']);
                                    this.setupOtherCards(2);

                                    if (this['open2']) {
                                        this['open2'].setVisible(false);
                                    }
                                } else {
                                    cc.log('data.Sipai = ' + data.Sipai);
                                }
                            }
                        } else {
                            if (users[this.pos1] && data.Users[i].UserID == users[this.pos1].ID) {
                                mRoom['CardList1'] = data.Users[i].Hand;
                                this.cardList1 = mCard.getOtherCardList(mRoom['CardList1']);
                                this.setupOtherCards(1);
                                this.open1.setWeiColor(1);
                            } else if (users[this.pos2] && data.Users[i].UserID == users[this.pos2].ID) {
                                mRoom['CardList2'] = data.Users[i].Hand;
                                cc.log('mRoom[\'CardList2\'] = ' + mRoom['CardList2']);
                                cc.log('open2 = ' + this.open2);
                                cc.log('mCard = ' + mCard);
                                this.cardList2 = mCard.getOtherCardList(mRoom['CardList2']);
                                this.setupOtherCards(2);
                                if (this.open2 && this.open2.setWeiColor)
                                    this.open2.setWeiColor(2);
                            } else if (users[this.pos3] && data.Users[i].UserID == users[this.pos3].ID) {
                                mRoom['CardList3'] = data.Users[i].Hand;
                                this.cardList3 = mCard.getOtherCardList(mRoom['CardList3']);
                                this.setupOtherCards(3);
                                this.open3.setWeiColor(3);
                            }
                        }
                    }
                }
            }
        },

        //房间内断开重连
        onRoleLoginOK: function (event) {
            var data = event;

            this.txtUserName0.setString(ellipsisStr(gameData.nickname, 5));
        },

        onLeaveOK: function (event) {
            var data = event;
            //如果是自己离开的消息。socket关闭
            if (data.Users[0] == gameData.uid) {
                if (gameData.switchVideo) {
                    AgoraUtil.closeVideo();
                }
                //cc.eventManager.removeAllListeners();
                gameData.roomId = 0;

                mRoom['CardList'] = null;

                showBoard('HallBoard');
            }
        },
        onJoinOK: function (event) {
            var data = event;
            if (data.Head.Result != null && data.Head.Result == -1) {
                if (gameData.switchVideo) {
                    AgoraUtil.closeVideo();
                }
            } else {
                this.setupPlayers();
            }
            eventManager.dispatchEvent(EventKey.ClubRoomPlayerStateRefresh);
        },

        processGameOver: function () {
            if (this.gameOverHuInfo == null) {
                playEffect('huangz');//胡不得
            } else {

                if (mRoom.wanfatype == mRoom.HENGYANG) {
                    this.playCPTPHEffect('hu', gameData.sex);
                } else {
                    if (this.gameOverData.WinnerZimo) {
                        this.playCPTPHEffect('zimo', gameData.sex);//自摸
                    } else {
                        this.playCPTPHEffect('hu', gameData.sex);
                    }
                }
            }
            this.setTurnInOver();

            // //结算飞金币
            // var winplayer = [];
            // var loseplayer = [];
            // var winnode1 = null;
            // var winnode2 = null;
            // var losenode1 = null;
            // var losenode2 = null;
            // for (var i = 0; i < this.gameOverData.Users.length; i++) {
            //     var gr = this.gameOverData.Users[i];
            //     var pos = mRoom.getUserPosIndex(gr.UserID);
            //     if(gr.Result > 0){
            //         winplayer.push(pos);
            //     }
            //     if(gr.Result < 0){
            //         loseplayer.push(pos);
            //     }
            // }
            // if(winplayer.length == 1 && loseplayer.length == 2){
            //     winnode1 = $("node.info"+winplayer[0]+".head"+winplayer[0], this.playersInfo);
            //     losenode1 = $("node.info"+loseplayer[0]+".head"+loseplayer[0], this.playersInfo);
            //     losenode2 = $("node.info"+loseplayer[1]+".head"+loseplayer[1], this.playersInfo);
            //     this.playCoinsFlyAnim(losenode1, winnode1, 10);
            //     this.playCoinsFlyAnim(losenode2, winnode1, 10);
            // }
            // if(winplayer.length == 2 && loseplayer.length == 1){
            //     winnode1 = $("node.info"+winplayer[0]+".head"+winplayer[0], this.playersInfo);
            //     winnode2 = $("node.info"+winplayer[1]+".head"+winplayer[1], this.playersInfo);
            //     losenode1 = $("node.info"[0]+".head"+loseplayer[0], this.playersInfo);
            //     this.playCoinsFlyAnim(losenode1, winnode1, 10);
            //     this.playCoinsFlyAnim(losenode1, winnode2, 10);
            // }
            // if(winplayer.length == 1 && loseplayer.length == 1){
            //     winnode1 = $("node.info"+winplayer[0]+".head"+winplayer[0], this.playersInfo);
            //     losenode1 = $("node.info"+loseplayer[0]+".head"+loseplayer[0], this.playersInfo);
            //     this.playCoinsFlyAnim(losenode1, winnode1, 10);
            // }

            //this.scheduleOnce(this.showGameResult, 1.5,true);
            if (this.gameOverData.XingCard && this.gameOverData.XingCard != 0) {
                this.scheduleOnce(this.showFanXingAni.bind(this), 0.3);
                this.scheduleOnce(this.showGameResult.bind(this), 1.35);
            } else {
                this.scheduleOnce(this.showGameResult.bind(this), .8);
            }
        },
        //金币转移的特效
        playCoinsFlyAnim: function (beginNode, endNode, count) {
            var beginPos = cc.p(0, 0);
            playEffect('vGold');
            if (beginNode) beginPos = beginNode.convertToWorldSpace(beginNode.getPosition());
            var endPos = cc.p(0, 0);
            if (endNode) endPos = endNode.convertToWorldSpace(endNode.getPosition());
            for (var i = 0; i < count; i++) {
                this.coinFly(beginPos, endPos, i);
            }
        },
        //一个金币飞舞
        coinFly: function (beginPos, endPos, i) {
            var sprite = new cc.Sprite(goldTexture);
            sprite.setPosition(cc.p(beginPos.x + 40, beginPos.y + 40));
            this.playersInfo.addChild(sprite, -1);
            sprite.runAction(cc.sequence(
                cc.delayTime(0.1 * i),
                // cc.jumpTo(0.5,
                //     cc.p(endPos.x - 30 + Math.floor(Math.random() * 61), endPos.y - 30 + Math.floor(Math.random() * 61)),
                //     30,
                //     1).easing(cc.easeOut(1.5)),
                cc.moveTo(0.5, cc.p(endPos.x + 40, endPos.y + 40)),
                cc.delayTime(0.2),
                cc.callFunc(function () {
                    sprite.removeFromParent(true);
                })
            ));
        },

        showFanXingAni: function () {
            this.nLaizi.removeAllChildren();
            var card = new Card();
            this.nLaizi.addChild(card);
            card.setPositionY(this.nLaizi.getPositionY());
            card.setPositionX(90);
            card.setData(this.gameOverData.XingCard, this.nLaizi, 2);
            if (this.gameOverData.XingCard == 0) {
                // fanxing.setVisible(false);
                card.setVisible(false);
                // fanxingnum.setVisible(false);
                this.nLaizi.setVisible(false);
            } else {
                this.nLaizi.setVisible(true);
                // fanxing.setVisible(true);
                card.setVisible(true);
                // fanxingnum.setVisible(true);
                if (window.huzi_anniu_type === 1) {
                    var animation_name = (mRoom.Fanxing == 'gen') ? 'genxing' : 'fanxing';
                    var zi_tx = playSpAnimation_hz('zi_tx', animation_name, false);
                    if (cc.sys.isObjectValid(zi_tx)) {
                        zi_tx.setPosition(cc.p(640, 360 + 150));
                        this.aniAct.addChild(zi_tx);
                    }
                } else {
                    //反省  动画
                    var sscname = (mRoom.Fanxing == 'gen') ? huzi.res.Phz_genxingAni : huzi.res.Phz_fanxingAni;
                    var ccsScene = ccs.load(sscname);
                    var fanxingAni = ccsScene.node;
                    fanxingAni.setName('fingerAnimation');
                    // console.log(fanxingAni.getContentSize().height);
                    fanxingAni.setPosition(cc.p(1280 / 2, 720 / 2 + 150));
                    fanxingAni.setPositionX(cc.winSize.width / 2);
                    this.addChild(fanxingAni, 100);
                    fanxingAni.setScale(.8);
                    fanxingAni.runAction(ccsScene.action);
                    ccsScene.action.play('action', true);
                    this.scheduleOnce(function () {
                        fanxingAni.removeFromParent();
                    }, 1);
                }

                this.scheduleOnce(function () {
                    var showfancard = new Card();
                    showfancard.setScale(.6);
                    showfancard.setData(this.gameOverData.XingCard, this, 1);
                    // console.log(showfancard.getContentSize().height / 2)
                    showfancard.setPosition(cc.p(1280 / 2, 720 / 2 + showfancard.getContentSize().height / 2 + 140));
                    showfancard.setPositionX(cc.winSize.width / 2);
                    this.addChild(showfancard, 101);
                    var movexy = card.convertToNodeSpace(cc.p(1280 / 2, 720 / 2));
                    // console.log(movexy);
                    showfancard.runAction(cc.sequence(
                        cc.scaleTo(0.25, -.6, .6)
                        , cc.scaleTo(0.30, .6, .6)
                        //, cc.spawn(cc.moveTo(0.5, this.nLaizi.x + 80, this.nLaizi.y - 20), cc.scaleTo(0.5, 0.5))
                        , cc.scaleTo(0.40, .8, .8)
                        , cc.removeSelf()
                    ));
                }, 0.1);
            }
        },
        showGameResult: function (isPlayMusic) {
            cc.sys.localStorage.setItem('Storage_handsCards', []);
            isPlayMusic = isPlayMusic;
            var gameResult = new PhzJieSuan(isPlayMusic);
            this.addChild(gameResult);
            gameResult.setLocalZOrder(3);
            gameResult.setName('gameResult');
            gameResult.setRoom(this, this.gameOverHuInfo, this.gameOverData, mRoom.isReplay);
            this.panelResult.setVisible(true);
        },

        onRoomResult: function (event) {
            var data = event;
            this.roomCleanData = data;
            this.setRoomState(ROOM_STATE_ENDED);

            if (gameData.jiesanSucess) {
                if (!mRoom.isReplay)
                    this.unscheduleUpdate();
                var roomclean = new PhzZongJieSuan();
                this.addChild(roomclean);
                roomclean.setLocalZOrder(2);
                roomclean.setName('roomclean');
                roomclean.setRoom(this, this.roomCleanData);
                this.roomCleanData = null;
                this.lastShowCard = null;
                this.imgAct.stopAllActions();
                this.imgAct.removeAllChildren();
                this.imgAct.setOpacity(0);
                this.huAni.setOpacity(0);
                mRoom.shouxing = false;
                mRoom.sxUserId = 0;
            }

            this.huAni.setOpacity(0);
        },
        showRoomClean: function () {
            if (this.getChildByName('roomclean')) return;
            if (this.roomCleanData == null || this.roomCleanData == undefined) return;
            // if(this.getChildByName('vote')){
            //     this.getChildByName('vote').removeFromParent();
            // }

            if (gameData.jiesanSucess)
                gameData.jiesanSucess = false;
            var roomclean = new PhzZongJieSuan();
            this.addChild(roomclean);
            roomclean.setLocalZOrder(2);
            roomclean.setName('roomclean');
            roomclean.setRoom(this, this.roomCleanData);
            this.roomCleanData = null;

            this.huAni.setOpacity(0);
        },
        initChatBtn: function () {
            if (mRoom.isReplay == true) {
                return;
            }
            var that = this;
            var btn_chat = this.chat;
            TouchUtil.setOnclickListener(btn_chat, function () {
                // var chatLayer = new ChatLayer('paohuzi');
                // that.addChild(chatLayer);
                showWindow('ChatWindow');
            });
        },

        setReady: function (uid, visible) {
            if (gameData.players && gameData.players.length) {
                for (var i = 0; i < gameData.players.length; i++) {
                    if (uid == gameData.players[i]['ID']) {
                        if (visible) {
                            gameData.players[i]['ready'] = 1;
                        } else {
                            gameData.players[i]['ready'] = 0;
                        }
                        break;
                    }
                }
            }
            this.refreshPlayersStates();

            var row = mRoom.getUserPosIndex(uid) || 0;
            var head = $('node.info' + row + '.head' + row, this.playersInfo);
            if (head == undefined || !cc.sys.isObjectValid(head)) {
                return;
            }
            var ready = head.getChildByName('ready');
            if (!ready) {
                if (row == 0) {
                    ready = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'ready_min.png');
                } else {
                    ready = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'ready.png');
                }
                ready.setName('ready');
                ready.setAnchorPoint(cc.p(0.5, 0.5));
                if (mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.QIYANG) {
                    ready.setPosition(cc.p((row == 0) ? 600 : ((row == 1 || row == 2) ? 90 : -15), 40));
                } else {
                    ready.setPosition(cc.p((row == 0) ? 600 : ((row == 1) ? 95 : -15), 40));
                }

                head.addChild(ready);
            }
            ready.setVisible(visible);
        },
        refreshPlayersStates: function () {
            if (this.assistantLayer && cc.sys.isObjectValid(this.assistantLayer)) {
                this.assistantLayer.refreshPlayersStates();
            }
        },
        setAllReadyVisible: function (flag) {
            for (var i = 0; i < mRoom.playerNum; i++) {
                var head = $('node.info' + i + '.head' + i, this.playersInfo);
                var ready = head.getChildByName('ready');
                if (!ready) {
                    if (i == 0) {
                        ready = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'ready.png');
                    } else {
                        ready = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'ready_min.png');
                    }
                    ready.setName('ready');
                    ready.setAnchorPoint(cc.p(0.5, 0.5));
                    ready.setPosition(cc.p((i == 0) ? 220 : ((i == 1) ? -40 : 120), (i == 1 || i == 2) ? 40 : 20));
                    head.addChild(ready);
                }
                ready.setVisible(flag);
            }
        },
        setZhuangjia: function (pos) {
            if (pos == undefined || pos < 0) return;
            //不足三人不显示庄家
            var users = gameData.players;
            if (users != undefined && users.length == this.playersNum) {
                for (var i = 0; i < this.playersNum; i++) {
                    var head = $('node.info' + i + '.head' + i, this.playersInfo);
                    var zhuang = head.getChildByName('zhuang');
                    if (!zhuang) {
                        zhuang = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'zhuang.png');
                        zhuang.setName('zhuang');
                        zhuang.setAnchorPoint(cc.p(0.5, 0.5));
                        zhuang.setPosition((i != 1) ? cc.p(0, 80) : cc.p(80, 80));
                        head.addChild(zhuang);
                    }
                    zhuang.setScale(0.8);
                    var index = mRoom.getUserIndex(gameData.uid);
                    zhuang.setVisible(((index + i) % this.playersNum == pos) ? true : false);
                }
            }
        },
        setPlayersStatus: function (event) {
            if (this._willShowAssist) {
                eventManager.dispatchEvent(EventKey.ClubPlayerEnterExit, gameData.players || []);
            }

            //console.log(event);
            var that = this;
            var data = event;
            if (data.UserID != gameData.uid) {
                //return;
            }
            if (data.GameStatus == 0) {
                //断线重连 此时已经打完至少一局 正在准备阶段
                if (data.SecondStart) {
                    this.isStart = true;
                    mRoom.isStart = true;
                }
                for (var i = 0; i < data.Users.length; i++) {
                    var uid = data.Users[i].UserID;
                    if (uid == gameData.uid) {
                        if (data.Users[i].ReadyValue == 1 || (uid != data.UserID && data.SecondStart)) {
                            //that.zhunbei.setVisible(false);
                        } else {
                            that.zhunbei.setVisible(true);
                        }
                    }
                    if (data.Users[i].ReadyValue == 1) {
                        that.setReady(uid, true);
                    } else {
                        that.setReady(uid, false);
                    }
                }
            }
            else {
                this.isStart = true;
                mRoom.isStart = true;
                this.zhunbei.setVisible(false);
                for (var i = 0; i < data.Users.length; i++) {
                    var uid = data.Users[i].UserID;
                    this.setReady(uid, false);
                }
            }
            eventManager.dispatchEvent(EventKey.ClubRoomPlayerStateRefresh);
        },
        beginReplay: function () {
            this.clearRoom();
            this.setupPlayers();
        },
        setDisconnect: function (uid, flag) {
            var row = mRoom.getUserPosIndex(uid);
            var head = $('node.info' + row + '.head' + row, this.playersInfo);
            if (head == undefined || !cc.sys.isObjectValid(head)) {
                return;
            }
            var disconnect = head.getChildByName('disconnect');
            if (!disconnect) {
                disconnect = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'lixian.png');
                disconnect.setName('disconnect');
                disconnect.setPosition(cc.p(head.getContentSize().width / 2, head.getContentSize().height / 2 - 2));
                disconnect.setScale(1.1);
                head.addChild(disconnect);
            }
            disconnect.setVisible(flag);
        },

        setDisconnect2: function (userPos) {
            var head = $('node.info' + userPos + '.head' + userPos, this.playersInfo);
            var disconnect = head.getChildByName('disconnect');
            if (!disconnect) {
                disconnect = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'lixian.png');
                disconnect.setName('disconnect');
                disconnect.setPosition(cc.p(head.getContentSize().width / 2, head.getContentSize().height / 2 - 2));
                disconnect.setScale(1.1);
                head.addChild(disconnect);
            }
            disconnect.setVisible(false);
        },

        onJushou_Status: function (event) {
            // var event = {"__instanceId":5398,"_type":6,"_eventName":125,"_userData":{"Users":[{"UserID":12879, "IsSet":0, "CanSet":1},
            //     {"UserID":12880, "IsSet":0, "CanSet":1},
            //     {"UserID":12881, "IsSet":0, "CanSet":1}]},"_currentTarget":null,
            //     getUserData: function () {
            //         return this._userData;
            //     }};
            var data = event;
            var canchupai = true;
            if (data && data.Users) {
                for (var i = 0; i < data.Users.length; i++) {
                    this.setJushou(data.Users[i].UserID, data.Users[i].IsSet, data.Users[i].CanSet);
                    if (data.Users[i].CanSet == 1 && data.Users[i].IsSet == 0) {
                        canchupai = false;
                    }
                }
            }
            this.setMyCardsTouch(canchupai);
        },
        setJushou: function (uid, isset, canset, status) {
            if (mRoom.wanfatype != mRoom.LEIYANG) return;
            var row = mRoom.getUserPosIndex(uid);
            var head = $('node.info' + row + '.head' + row, this.playersInfo);
            var info = $('node.info' + row, this.playersInfo);
            //举手中
            var jushou = head.getChildByName('jushou');
            if (!jushou) {
                jushou = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'jushouzhong2.png');
                jushou.setName('jushou');
                jushou.setAnchorPoint(cc.p(0.5, 0.5));
                var jushoupos = cc.p(150, 150);
                if (row == 1) {
                    jushoupos = cc.p(-20, 10);
                } else if (row == 2) {
                    jushoupos = cc.p(120, 30);
                }
                jushou.setPosition(jushoupos);
                head.addChild(jushou);
                jushou.setVisible(false);
            }
            if (jushou) {
                //已举手
                if (isset == 1) {
                    var yjushoupos = cc.p(70, 60);
                    // if(row == 1){
                    //     yjushoupos = cc.p(-20, 10);
                    // }else if(row == 2){
                    //     yjushoupos = cc.p(120, 30);
                    // }
                    jushou.setVisible(true);
                    jushou.setTexture(huzi.resPath+'dynamicRes/' + 'yijushou3.png');
                    jushou.setPosition(yjushoupos);
                }
                //举手中
                if (canset == 1 && isset == 0) {
                    jushou.setVisible(true);
                    jushou.setTexture(huzi.resPath+'dynamicRes/' + 'jushouzhong2.png');
                }
                //不举手
                if (isset == 2) {
                    jushou.setVisible(false);
                }
            }
            if (gameData.uid == uid) {
                if (canset == 1 && isset == 0) {
                    this.jushou.setVisible(true);
                    this.bujushou.setVisible(true);
                } else {
                    this.jushou.setVisible(false);
                    this.bujushou.setVisible(false);
                }
            }
            if (status == false) {
                jushou.setVisible(false);
            }
        },
        setMyCardsTouch: function (status) {
            this.isCanChuPai = status;
            // var cardList = this.nCards0.getChildren();
            // for (var i = 0; i < cardList.length; i++) {
            //     var card = cardList[i];
            //     card.setTouchEnableStatus(status);
            // }
        },
        //报警
        onBaojing: function (event) {
            var data = event;
            for (var i = 0; i < data.Users.length; i++) {
                this.setBaojing(data.Users[i].UserID, data.Users[i].Stat);
            }
        },
        //反省
        onFanXing: function (event) {
        },
        onWangdiao: function (event) {
        },
        setBaojing: function (uid, status) {
            var row = mRoom.getUserPosIndex(uid);
            var head = $('node.info' + row + '.head' + row, this.playersInfo);
            var info = $('node.info' + row, this.playersInfo);
            //举手中
            var baojing = head.getChildByName('baojing');
            if (!baojing) {
                baojing = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'baojingzhong1.png');
                baojing.setName('baojing');
                baojing.setAnchorPoint(cc.p(0.5, 0.5));
                var jushoupos = cc.p(50, 150);
                if (row == 0) {
                    jushoupos = cc.p(340, 60);
                } else if (row == 1) {
                    jushoupos = cc.p(-180, 60);
                } else if (row == 3 || row == 2) {
                    jushoupos = cc.p(50, -30);
                }
                baojing.setPosition(jushoupos);
                head.addChild(baojing);
                baojing.setVisible(false);
            }
            if (baojing) {
                if (status == 2) {
                    //已报警
                    baojing.setVisible(true);
                    baojing.setTexture((row == 2 || row == 3)
                        ? huzi.resPath+'dynamicRes/' + 'baojing1.png' : huzi.resPath+'dynamicRes/' + 'baojing2.png');
                } else if (status == 1) {
                    //报警中
                    baojing.setVisible(true);
                    baojing.setTexture((row == 2 || row == 3)
                        ? huzi.resPath+'dynamicRes/' + 'baojingzhong1.png' : huzi.resPath+'dynamicRes/' + 'baojingzhong2.png');
                } else {
                    baojing.setVisible(false);
                }
            }
            if (uid == gameData.uid && status == 1) {
                //0:不能设置报警  1:能设置，但是没有设置  2:已经报警  3:选择不报警
                showMessageBox('选择报警或者不报警，确定（报警），取消（不报警）。', function () {
                    network.sendPhz(5000, 'Baojing/2');
                }, function () {
                    network.sendPhz(5000, 'Baojing/3');
                });
            }
        },
        onNiao_Status: function (event) {
            var data = event;
            this.invite.setVisible(false);
            this.invite_liaobei.setVisible(false);
            this.copyroom.setVisible(false);
            this.tuichu.setVisible(false);
            this.jiesan.setVisible(false);

            var isSelfSelect = false;
            for (var i = 0; i < data.Users.length; i++) {
                this.setSelectNiao(data.Users[i].UserID, data.Users[i].IsSet, true, data.Users[i].TuoNiao);
                if (data.Users[i].UserID == gameData.uid && data.Users[i].IsSet == 1) {
                    isSelfSelect = true;
                }
            }
            if (isSelfSelect == false && mRoom.isReplay != true) {
                //准备娄底放炮罚  加抓鸟选项
                if (mRoom.niao == true && this.zhuoniao == null) {
                    // var zhuoniao = new PhzZhuoniao()
                    // this.addChild(zhuoniao);
                    // this.zhuoniao = zhuoniao;
                }
            }
        },
        //选鸟
        setSelectNiao: function (uid, niaotype, hide, niaonum) {
            if (mRoom.niao != true) return;
            var row = mRoom.getUserPosIndex(uid);
            var head = $('node.info' + row + '.head' + row, this.playersInfo);
            var niao = head.getChildByName('niao');
            if (!niao) {
                niao = new cc.Sprite((row == 0) ? huzi.resPath+'dynamicRes/' + 'zhuoniao/znzhong2.png' : huzi.resPath+'dynamicRes/' + 'zhuoniao/znzhong1.png');
                niao.setName('niao');
                niao.setAnchorPoint(cc.p(0.5, 0.5));
                niao.setPosition((row == 0) ? cc.p(150, 50) : cc.p(50, -50));
                head.addChild(niao);
            }
            var info = $('node.info' + row, this.playersInfo);
            var niaoLabel = $('niaonum' + row, info);
            if (niaoLabel) {
                niaoLabel.setVisible(false);
                if (niaonum != undefined) niaoLabel.setString('拖鸟:' + niaonum);
            }

            if (hide == false) {
                niao.setVisible(false);
            } else {
                niao.setVisible(true);
                if (niaotype == 0) {
                    niao.setTexture((row == 0) ? huzi.resPath+'dynamicRes/' + 'zhuoniao/znzhong2.png' : huzi.resPath+'dynamicRes/' + 'zhuaniao/znzhong1.png');
                } else {
                    niao.setTexture((row == 0) ? huzi.resPath+'dynamicRes/' + 'zhuoniao/yzn2.png' : huzi.resPath+'dynamicRes/' + 'zhuaniao/yzn1.png');
                }
            }
            //如果是自己 并且没设置 显示捉鸟界面
            if (uid == gameData.uid && niaotype == 0 && mRoom.isReplay != true && this.isStart == true) {
                //准备娄底放炮罚  加抓鸟选项
                if (mRoom.niao == true && this.zhuoniao == null) {
                    // var zhuoniao = new PhzZhuoniao()
                    // this.addChild(zhuoniao);
                    // this.zhuoniao = zhuoniao;
                }
            }
        },
        setNiaoNumVisible: function (uid, visible) {
            if (mRoom.niao == true) {
                var row = mRoom.getUserPosIndex(uid);
                var info = $('node.info' + row, this.playersInfo);
                var head = $('node.info' + row + '.head' + row, this.playersInfo);
                var niaoLabel = $('niaonum' + row, info);
                if (niaoLabel) {
                    niaoLabel.setVisible(visible);
                }
                var niao = head.getChildByName('niao');
                if (niao) {
                    niao.setVisible(!visible);
                }
            }
        },
        hideJuShou: function (uid, visible) {
            var row = mRoom.getUserPosIndex(uid);
            var info = $('node.info' + row, this.playersInfo);
            var head = $('node.info' + row + '.head' + row, this.playersInfo);

            if (cc.sys.isObjectValid(head)) {
                var jushowu = head.getChildByName('jushou');
                if (jushowu) {
                    jushowu.setVisible(visible);
                }
            }
        },
        //更换字体
        setCardFont: function () {
            for (var i = 0; i < this.playersNum; i++) {
                var open = this['open' + i];
                var openChileren = open.getChildren();
                for (var j = 0; j < openChileren.length; j++) {
                    openChileren[j].resetCardImg();
                }
                var out = this['out' + i];
                var outChileren = out.getChildren();
                for (var j = 0; j < outChileren.length; j++) {
                    outChileren[j].resetCardImg();
                }
            }
            var mycards = this.nCards0.getChildren();
            for (var j = 0; j < mycards.length; j++) {
                mycards[j].resetCardImg();
            }
            this.setupCards();
        },
        getOriginalPos: function () {
            return 0;
        },

        setTingPaiList: function (event) {
            var data = event;
            tingData = data['TingCards'];
            this.showTingPaiOnDesk(tingData);
            tishiData = [];
            var handList = this.nCards0.getChildren();
            for (var i = 0; i < handList.length; i++) {
                var card = handList[i];
                card.setTingMark(false);
            }
        },
        setTishiList: function (event) {
            this._lastTingEvent = event;
            var that = this;
            var data = event;
            tingData = [];
            this.showTingPaiOnDesk(tingData);
            tishiData = data['TingCards']; //
            this.scheduleOnce(function () {
                var handList = that.nCards0.getChildren();
                for (var i = 0; i < handList.length; i++) {
                    var card = handList[i];
                    for (var j = 0; j < tishiData.length; j++) {
                        if (card.data == tishiData[j]['Card'])
                            card.setTingMark(true);
                    }
                }
            }, .2);
        },
        showTingPaiOnDesk: function (data, type) {
            this.tingNode.removeAllChildren();
            if (type)
                this.tingNode.setOpacity(255);
            else
                this.tingNode.setOpacity(90);
            if (!data || data.length == 0)
                return;
            var delayX = 32;
            var _len = data.length;
            for (var i = 0; i < _len; i++) {
                var tingCardInfo = data[i];
                var sprite = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'tishi/huzi_ting_' + tingCardInfo['Card'] + '.png');
                this.tingNode.addChild(sprite);
                var posX = _len % 2 == 0 ? (-(_len * delayX / 2) + 12 + i * delayX) : (-(_len * delayX / 2) + 12 + i * delayX);
                sprite.setPositionX(posX);
                var textFont = new cc.LabelBMFont();
                textFont.setFntFile(res.huzi_ting_fnt);
                textFont.setPosition(cc.p(posX, -27));
                textFont.setString(tingCardInfo['Left']);
                this.tingNode.addChild(textFont);
            }
            if (_len > 0) {
                var tingSprite = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'tishi/huzi_ting.png');
                this.tingNode.addChild(tingSprite);
                tingSprite.setPositionX(_len % 2 == 0 ? (-(_len * delayX / 2) + 12 - delayX - 5) : (-(_len * delayX / 2) + 12 - delayX - 5));
            } else {
                this.tingNode.removeAllChildren();
            }
        },
        clearTingPai: function () {
            var handList = this.nCards0.getChildren();
            for (var i = 0; i < handList.length; i++) {
                var card = handList[i];
                card.setTingMark(false);
            }
            this.tingNode.removeAllChildren();
        },
        resetCards: function () {
            this.nCards0.removeAllChildren();
            var cardList = mCard.getCardList();
            this.cardList = cardList;
            this.setupCards();
        },
        getEffectEmojiPos: function (caster, patient, isNotMid) {
            var self = this;
            var pos = {};
            // var infoCaster = $('info' + caster);
            var infoCaster = $('node.info' + caster + '.head' + caster + '.head', this.playersInfo);
            // pos[caster] = infoCaster ? infoCaster.convertToWorldSpace($('info' + caster + '.head').getPosition()) : cc.p(cc.winSize.width / 2, cc.winSize.height / 2);
            pos[caster] = infoCaster ?
                infoCaster.convertToWorldSpace($('node.info' + caster + '.head' + caster + '.head', this.playersInfo).getPosition()) : cc.p(cc.winSize.width / 2, cc.winSize.height / 2);
            // var infoPatient = $('info' + patient);
            var infoPatient = $('node.info' + patient + '.head' + patient + '.head', this.playersInfo);
            // pos[patient] = (patient != self.getOriginalPos() && infoPatient) || isNotMid ? infoPatient.convertToWorldSpace($('info' + patient + '.head').getPosition()) : cc.p(cc.winSize.width / 2, cc.winSize.height / 2);
            pos[patient] = (patient != self.getOriginalPos() &&
                infoPatient) || isNotMid ?
                infoPatient.convertToWorldSpace($('node.info' + patient + '.head' + patient + '.head', this.playersInfo).getPosition()) : cc.p(cc.winSize.width / 2, cc.winSize.height / 2);
            return pos;
        },
        //获取自己的ChatInfo节点
        getChatInfoNode: function (_idx) {
            var ChatInfoNode = null;
            var idx = _idx;
            var head = $('node.info' + idx, this.playersInfo);
            if (head) {
                ChatInfoNode = $('ChatInfo', head);
            }
            return ChatInfoNode;
        },
        getRowByUid: function (uid) {
            //麻将和跑胡子坐标转换
            var row = mRoom.getUserPosIndex(uid);
            return row;
        }

    });
    exports.PhzLayer = PhzLayer;
    exports.PhzLayer.getCardImg = getCardImg;
})(window);